Ajax deletes data and views data, and ajax deletes data to view

Source: Internet
Author: User

Ajax deletes data and views data, and ajax deletes data to view

1. Find a table in the database:

Color Table

2. Home Page

The Code on the home page uses tbody;

The role of TBODY is:

You can control the download of table branches to increase the download speed.

(When a webpage is opened, all the table content is downloaded before it is displayed. You can download part of the table content from a branch to reduce the user waiting time.

The purpose of using TBODY is to make the code included in the table not be displayed after the entire table is parsed. That is to say, if multiple rows exist, if a TBODY row is obtained, you can display a row first.

The BODY is an HTML text BODY. an HTML file has only one BODY, and multiple tbodies can exist in the TABLE.

The TBODY label can be used to control the download of table branches. When the table content is large, it is more practical to add and at the branch download location,

For example:

The reference content is as follows: head1head2 is displayed first, first, then, and then foot1foot2.

Note:

* 1. The TBODY element is not rendered in the browser.

* 2. When cells in different rows are merged, do not add the TBODY label to the row of each cell.

Tip: The valid tags contained in the tbody element are: TD, TH, and TR, which indicate that the running of the Code in this example will not be effective, because the table contains less content,

The results can be seen only when there is a large amount of data and a large number of table nesting.

Homepage code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Figure:

The callback function is empty and will be written back later;

Next, load the page:

Display: traverses the array to display the table content, specifically:

<? Phpinclude ("db. class. php "); $ db = new db (); $ SQL =" select * from min "; $ arr = $ db-> Query ($ SQL ); // traverse $ str = ""; foreach ($ arr as $ v) {$ str = $ str. implode ("-", $ v ). "|"; // use-to combine $ v. The combination is 1-red, 2-blue, separated by |, the combination is 1-red | 2-Blue |} echo $ str;

Let's take a look at the output:

Add a vertical line at the end to remove the vertical line:

$ Str = substr ($ str, 0, strlen ($ str)-1); // capture a string: Starting from 0th, extract its length-1 // strlen to obtain the string length

Let's take a look:

Now write the callback function:

<Script> $. ajax ({url: "jiazai. php ", // display all data without writing data dataType:" TEXT ", success: function (data) {var str =" "; var hang = data. split ("|"); // split the string for (var I = 0; I 

Go to the following page:

3. Now you can write and delete:

First, add the delete button to the last cell and pass a primary key value:

"</Td> <td>" + "<input type = 'button 'IDs = '" + lie [0] + "'class =' SC 'value = 'delete' /> "+ // The primary key value in ids" </td> </tr> ";

 

Add an event to the delete button and call the Ajax method:

**

Differences between Asynchronization and synchronization:

Synchronization must wait for the returned results to continue. asynchronous does not have to wait. Generally, you need to listen for asynchronous results.

Synchronization is performed in a queue in a straight line. asynchronous synchronization does not take place in a queue.

**

// Add an event $ (". SC "). click (function () {var ids = $ (this ). attr ("ids"); $. ajax ({url: "shanchu. php ", data: {ids: ids}, dataType:" TEXT ", type:" POST ", success: function (d ){}});})

Callback functions, etc;

Continue to delete the processing page:

<?phpinclude ("db.class.php");$db = new db();$ids = $_POST["ids"];$sql = "delete from min WHERE ids='{$ids}'";if($db ->Query($sql,0)){  echo "ok";}else{  echo "no";}

In this case:

Click Delete. After deletion, the page will not be refreshed,

If you want him to automatically load data, he needs to encapsulate the code for loading data into a method, and call this method when deleting it.

Homepage code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head> <meta http-equiv =" Content-Type "content =" text/html; charset = UTF-8 "/> <title> untitled document </title> <script src =" jquery-1.11.2.min.js "> </script> 

Code for deleting a page:

<?phpinclude ("db.class.php");$db = new db();$ids = $_POST["ids"];$sql = "delete from min WHERE ids='{$ids}'";if($db ->Query($sql,0)){  echo "ok";}else{  echo "no";}

The above section describes how to use Ajax to delete data and view data. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.