Ajax遍歷jSon后對每一條數(shù)據(jù)進行相應的修改和刪除(代碼分享)
更新時間:2016年11月25日 14:09:16 作者:爸爸去哪了2之熊貓三胞胎
這篇文章主要介紹了Ajax遍歷jSon后對每一條數(shù)據(jù)進行相應的修改和刪除的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
$.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); }); } } });
以上所述是小編給大家介紹的Ajax遍歷jSon后對每一條數(shù)據(jù)進行相應的修改和刪除,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- Ajax的jsonp方式跨域獲取數(shù)據(jù)的簡單實例
- JQuery的ajax獲取數(shù)據(jù)后的處理總結(html,xml,json)
- 用ajax傳遞json到前臺中文出現(xiàn)問號亂碼問題的解決辦法
- Spring MVC 中 AJAX請求并返回JSON的示例
- jQuery使用ajax方法解析返回的json數(shù)據(jù)功能示例
- javascript解析ajax返回的xml和json格式數(shù)據(jù)實例詳解
- jQuery基于ajax操作json數(shù)據(jù)簡單示例
- 原生ajax處理json格式數(shù)據(jù)的實例代碼
- php+ajax+json 詳解及實例代碼
- ajax與json 獲取數(shù)據(jù)并在前臺使用簡單實例
相關文章
Ajax 提交表單數(shù)據(jù)到入庫的全盤操作流程分享
以下是Ajax 提交表單數(shù)據(jù)到入庫的全盤操作流程,希望本文對廣大php開發(fā)者有所幫助,感謝閱讀本文2014-01-01解決spring mvc 返回json數(shù)據(jù)到ajax報錯parseerror問題
最近使用ajax接收spring mvc傳過來的json數(shù)據(jù)時總是出現(xiàn)parseerror的錯誤,下面通過本文給大家分享spring mvc 返回json數(shù)據(jù)到ajax報錯parseerror問題的解決方法,需要的朋友參考下吧2017-05-05pushState、replaceState、onpopstate 實現(xiàn)Ajax頁面的前進后退刷新
這篇文章主要介紹了pushState、replaceState、onpopstate 實現(xiàn)Ajax頁面的前進后退刷新的相關資料,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2016-11-11