Home > Article > Web Front-end > Ajax traverses jSon to modify and delete data
This time I will bring you Ajax traversal jSon to modify and delete data , what are the precautions for Ajax traversal jSon to modify and delete data, the following is a practical case, Let’s take a look.
No more nonsense, I will just post the code for you. The specific code is as follows:$.ajax({ url: "/business/findpersons.json", dataType: "json", type:"GET", success: function(doc) { var objs=eval(doc); for (var i = 0; i < objs.length; i++){ var personid=objs[i].personId; var name=objs[i].personName; var email=objs[i].personEmail; 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='删除' name="+i+" class='deletePersonBut'></th>"+ "<th><input type='button' value='修改' name="+i+" class='updataPersonBut'></th>"+ "</tr>" ); var getA = "#personList .deletePersonBut[name="+ i + "]";//就这里获取的原因,那个i=objs.length的原因,感觉应该就是闭包的问题。 $(getA).click(function(){ var thid=$(this).parent(); var pid=thid.children(".deletePersonBut").attr('name'); alert(objs[pid].personId); }); var getA = "#personList .updataPersonBut[name="+ i + "]";//就这里获取的原因,那个i=objs.length的原因,感觉应该就是闭包的问题。 $(getA).click(function(){ var thid=$(this).parent(); var pid=thid.children(".updataPersonBut").attr('name'); alert(objs[pid].personId); }); } } });I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website! Recommended reading:
How to implement AJAX request array
How to deal with ajax parameters that are too long and cannot be submitted
The above is the detailed content of Ajax traverses jSon to modify and delete data. For more information, please follow other related articles on the PHP Chinese website!