ajax數(shù)據(jù)返回進(jìn)行遍歷的實(shí)例講解
后臺(tái)返回的數(shù)據(jù):
{"receiveList":[{"receive_dept_id":"1007873","receive_dept_desc":"區(qū)公司領(lǐng)導(dǎo)","guid":"2016112316042622494230","receive_platform_id":"001"},{"receive_dept_id":"1007876","receive_dept_desc":"主任","guid":"2016112316042626240391","receive_platform_id":"001"}]}
其實(shí)仔細(xì)分析返回的格式,很簡單,就是一個(gè)Map,里面放了一個(gè)List,List里面有各種參數(shù)。
前端頁面的請求
$.ajax({ url:"/moduleAuthen/default.do?method=loadAllReceive", dataType:"json", //返回的數(shù)據(jù)是json 格式 data:$("#fom1").serialize, //提交id為form1的所有參數(shù) success:function(data){ var json =data.receiveList; //第一種方式的遍歷 for(var index in json){ //其實(shí)index 就是個(gè)索引 var guid =json[index].guid; var receive_dept_desc =json[index].receive_dept_desc; } //還有一種jquery 方式的遍歷,效果其實(shí)是一樣的,拿到后臺(tái)返回我們的數(shù)據(jù),我們就可以進(jìn)行各種操作了。 $.each(json,index){ var guid =json[index].guid; var receive_dept_desc =json[index].receive_dept_desc; } } }) { "compress":[ <#if d_live??> <#-- 參數(shù):int pageNo --> <#assign page = request.getParameter("page")!"null"> <#assign page = request.getParameter("page")!"null"> <#if page!="null" && page!=""> <#assign page = page?number> <#else> <#assign page=1> </#if> <#-- 參數(shù):int pageSize--> <#assign pagesize = request.getParameter("pagesize")!"null"> <#if pagesize!="null" && pagesize!=""> <#assign pagesize = pagesize?number> <#else> <#assign pagesize=10> </#if> <#if d_live.getLiveInfoList( page,pagesize,"3")??> <#assign pagedContent = d_live.getLiveInfoList( page,pagesize,"3")!"null"> <#if pagedContent.getContent()??> <#assign LiveInfo = pagedContent.getContent()!"null"> <#-- LiveInfo數(shù)據(jù)源 --> <#if LiveInfo??> <#list LiveInfo as liveInfo> <#assign liveId = liveInfo.getLiveId()!"null"> <#assign liveInfoUrl = d_live.getLiveInfo("${liveId}")!"null"> <#assign liveUrl = liveInfoUrl.getPlayUrl()!"null"> <#-- 直播鏈接地址 --> {"liveId":"${liveId}","liveUrl":"${liveUrl}"} <#if liveInfo_has_next> , </#if> </#list> </#if> </#if> </#if> </#if> ] } /*異步數(shù)據(jù)*/ var liveId= $("#liveId").val(); var asyurl="http://wap.cmread.com/rbc/t/liveindex.jsp?vt=9"+"&ol=560395"; alert("異步請求之前"); setTimeout(function(){ alert("進(jìn)入定時(shí)器,還沒有異步"); $.ajax({ url:asyurl, type:"POST", dataType:"json", success: function(data){ alert("異步獲取數(shù)據(jù)成功"); //var data = eval('('+data+')'); compress = data.compress; for(var i=0;i<compress.length;i++){ alert("進(jìn)入for循環(huán)"); var asyliveId=compress[i].liveId; if(asyliveId==liveId){ alert("匹配相同"); var liveUrl=compress[i].liveUrl; $("#live").find("source").attr("src",liveUrl); } } alert("執(zhí)行第一次支部請求,改變地址是"+$("#live").find("source").attr("src")); },error:function(){ console.log("error"); } }); },3000);
以上這篇ajax數(shù)據(jù)返回進(jìn)行遍歷的實(shí)例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
深入淺析Nginx實(shí)現(xiàn)AJAX跨域請求問題
AJAX從一個(gè)域請求另一個(gè)域會(huì)有跨域的問題。那么如何在nginx上實(shí)現(xiàn)ajax跨域請求呢?此問題難住很多朋友,下面小編給大家?guī)砹薔ginx實(shí)現(xiàn)AJAX跨域請求問題的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2016-06-06$.ajax中contentType: “application/json” 的用法詳解
這篇文章主要介紹了$.ajax中contentType: “application/json” 的用法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10AJAX POST數(shù)據(jù)中有特殊符號(hào)(轉(zhuǎn)義字符)導(dǎo)致數(shù)據(jù)丟失的解決方法
這篇文章主要介紹了Ajax發(fā)送轉(zhuǎn)義字符 、>、<、"接收數(shù)據(jù)不全問題,需要的朋友可以參考下2023-06-06ajax實(shí)現(xiàn)用戶名校驗(yàn)的傳統(tǒng)和jquery的$.post方式(實(shí)例講解)
下面小編就為大家分享一篇ajax實(shí)現(xiàn)用戶名校驗(yàn)的傳統(tǒng)和jquery的$.post方式的實(shí)例講解,具有很好的參考價(jià)值,希望對大家有所幫助2017-12-12ajax實(shí)現(xiàn)服務(wù)器與瀏覽器長連接的功能
這篇文章主要介紹了ajax實(shí)現(xiàn)服務(wù)器與瀏覽器長連接的功能的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-04-04Jquery版本導(dǎo)致Ajax不執(zhí)行success回調(diào)函數(shù)
這篇文章主要介紹了Jquery Ajax不執(zhí)行success回調(diào)函數(shù)的原因及解決方法2014-04-04ajax的定時(shí)調(diào)用每5秒調(diào)用一次
這篇文章主要介紹了關(guān)于ajax的定時(shí)調(diào)用,本例為每5秒調(diào)用一次,大家可以根據(jù)自己的需求更改2014-05-05ajax原理總結(jié)附簡單實(shí)例及其優(yōu)點(diǎn)
在工作中用了Ajax N多次了,也看過一些相關(guān)方面的書籍,也算是認(rèn)識(shí)了它,本文對ajax原理坐下總結(jié),需要的朋友可以參考下2014-04-04