JQuery ajax dynamic Append CREATE table incompatible IE8

Source: Internet
Author: User

In many cases, using JS (jQuery1.10) Dynamic to create some styles, the dynamic interaction of the page is very convenient

However, different browsers for the dynamic generation is not very compatible, the incompatible IE8 met here, share with you

Code:

JSON data

Data.json

[{"Name": "Ajax", "Job": "Manong"},{"name": "JS", "Job": "Diaosi"}]

HTML page

<table class= "Ajaxappend" >

<thead></thead>

<tbody></tbody>

</table>

JS file

$document. Ready (function () {

. Ajax (Function () {

Type: "Post",

URL: "Data.json",

Success:function (data) {

$ (" . Ajaxappend tbody"). Append ("<t r >" );

$ (". Ajaxappend thead"). Append ("<th>name</th>");

$ (". Ajaxappend thead"). Append ("<th> job </th>");

$ (". Ajaxappend tbody"). Append ("</tr>");

for (int i = 0,l = Data.length; i < l; i = i+1) {

$ (". Ajaxappend tbody"). Append ("<t r >");

for (var key in Data[i]) {

$ (". Ajaxappend tbody"). Append ("<td>" +data[i][key]+ "</td>");

}

$ ( ". Ajaxappend tbody"). Append ("</t r >" );

}

}

});

});


The above effect is able to generate tables dynamically under Firefox.

But not in the IE8, after several verification, speculation, ie on the dynamic append content requirements, need to have a full meaning of HTML together append into the code


Modify the following

$document. Ready (function () {

. Ajax (Function () {

Type: "Post",

URL: "Data.json",

Success:function (data) {

var head= "";

var body = "";

Head = head + "<tr><th>name</th><th>job</th></tr>";

for (int i = 0,l = Data.length; i < l; i = i+1) {

Body = body + "<tr>";

for (var key in Data[i]) {

Body = Body + "<td>" +data[i][key]+ "</td>";

}

Body = body + "</tr>";

}

· $ (". Ajaxappend tbody"). Append (body);

}

});

});

So the IE8 and Firefox can be displayed properly.


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.