Home  >  Article  >  php教程  >  Ajax traverses jSon and modifies and deletes each piece of data accordingly.

Ajax traverses jSon and modifies and deletes each piece of data accordingly.

高洛峰
高洛峰Original
2016-12-10 09:32:141479browse

No more nonsense, let me 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=&#39;button&#39; value=&#39;删除&#39; name="+i+" class=&#39;deletePersonBut&#39;></th>"+
"<th><input type=&#39;button&#39; value=&#39;修改&#39; name="+i+" class=&#39;updataPersonBut&#39;></th>"+
"</tr>"
);
var getA = "#personList .deletePersonBut[name="+ i + "]";//就这里获取的原因,那个i=objs.length的原因,感觉应该就是闭包的问题。
$(getA).click(function(){
var thid=$(this).parent();
var pid=thid.children(".deletePersonBut").attr(&#39;name&#39;);
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(&#39;name&#39;);
alert(objs[pid].personId);
});
}
}
});


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Ajax usage code analysisNext article:Ajax usage code analysis