Jquery AJAX obtains data dynamically and generates table examples

Source: Internet
Author: User

The following jquery Ajax code features are: request data and traverse the data, dynamically creating table elements to add to the page.

function Shop_detail (seller_id,shop_id,product_id) {
$.ajax ({
URL: "__url_seller__/popdata/ajaxdetailaction",
Method: "POST",
DataType: "JSON",
Data: {seller_id:seller_id, shop_id:shop_id, product_id:product_id},
Beforesend:function () {
$ ("#s_" +seller_id+ ' _ ' +product_id). html (' Wait ... ');
}
). Done (function (data) {
Tbbody = ';
tr = ' <th class= ' w75 > Product </th><th> activity time </th><th> Sales </th><th> coupon Amount </th ><th> Full Reduction </th><th> order number </th><th> after sales </th><th> after sales rate </th> ';
$.each (data, function (I, n) {
if (i%2==1) {
class_html = ' class= ' Tab_gre ';
}else{
class_html = ';
}
Tbbody + + ' <tr ' + class_html + ' ><td align= "left" ><a href= "' + N.url + '" target= "_blank" > ' + n.product_na Me + "</a></td>" + "<td align= ' center ' >" + n.start_time + "-" + N.end_time + "</td>" + "<td Ali gn= ' center ' > "+ n.sale_total_amount +" </td> "+" <td align= ' center ' > "+ n.coupon_sale_total_amount +" < /TD> "+" <td align= ' center ' > "+ n.discount_sale_total_amount +" </td> "+" <td align= ' center ' > "+ N.order_count + "</td>" + "<td align= ' center ' >" + n.reject_total_amount + "</td>" + "<td align=" Cente R ' > ' + n.return_rate + "</td></tr>";
$ ("#tbody_" +seller_id+ "_" +product_id). Empty (). HTML (TR). Append (Tbbody);
$ ("#s_" +seller_id+ ' _ ' +product_id). html (' view ');
});
});
}

The effect is as follows:

Clicking on the view will AJAX request all the items in the schedule and show that the PHP section is responsible for statistics and conversion to JSON format data.

Include: Ajax request data, get JSON data and traversal, dynamic append table tr,td elements, alternate colors and so on.

This example demonstrates the ability to dynamically create a table TR,TD and append the display to Ajax.

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.