Ajax traverses the JSON to modify and delete each piece of data (code sharing) _ajax related

Source: Internet
Author: User
Tags closure

Nonsense not to say more, directly to everyone to paste the code, the specific code as follows:

$.ajax ({url: "/business/findpersons.json", DataType: "JSON", type: "Get", Success:function (Doc) {var objs=eval (doc); fo R (var i = 0; i < objs.length i++) {var personid=objs[i].personid; var Name=objs[i].personname; var email=objs[i].pers
Onemail;
var sector=objs[i].personsector;
var position=objs[i].personposition;
var Password=objs[i].personpassword;
$ ("#personList thead"). Append ("<tr>" + "<th>" +name+ "</th>" + "<th>" +password+ "</th>" + "<th>" +email+ </th> "+" <th> "+position+" </th> "+" <th><input type= ' button ' value= ' Delete ' name= ' +i+ ' class= ' deletepersonbut ' ></th> ' + ' <th><input type= ' button ' value= ' Modify ' name= ' +i+ '
class= ' updatapersonbut ' ></th> ' + "</tr>"); 
var geta = "#personList. Deletepersonbut[name=" + i + "]";//The reason for this, the reason for that i=objs.length, the feeling should be the problem of closure. $ (Geta). Click (function () {var thid=$ (this). parent (); var pid=thid.children (". Deletepersonbut"). attr (' name '); alert ( Objs[pid].personid);
}); 
var geta = "#personList. Updatapersonbut[name=" + i + "]";//The reason for this, the reason for that i=objs.length, the feeling should be the problem of closure. $ (Geta). Click (function () {var thid=$ (this). parent (); var pid=thid.children (". Updatapersonbut"). attr (' name '); alert ( 
Objs[pid].personid);
}); } 
}
});

The above is a small series to introduce the AJAX traversal JSON after each of the data to modify and delete the corresponding, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.