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ì)分析返回的格式,很簡(jiǎn)單,就是一個(gè)Map,里面放了一個(gè)List,List里面有各種參數(shù)。
前端頁(yè)面的請(qǐng)求
$.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("異步請(qǐng)求之前");
setTimeout(function(){
alert("進(jìn)入定時(shí)器,還沒(méi)有異步");
$.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í)行第一次支部請(qǐng)求,改變地址是"+$("#live").find("source").attr("src"));
},error:function(){
console.log("error");
}
});
},3000);
以上這篇ajax數(shù)據(jù)返回進(jìn)行遍歷的實(shí)例講解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
[ASP.NET AJAX]Function對(duì)象及Type類的方法介紹
[ASP.NET AJAX]Function對(duì)象及Type類的方法介紹...2007-01-01
js實(shí)現(xiàn)簡(jiǎn)單實(shí)用的AJAX完整實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)簡(jiǎn)單實(shí)用的AJAX的方法,以完整實(shí)例形式分析了ajax無(wú)刷新調(diào)用的具體實(shí)現(xiàn)步驟與相關(guān)技巧,代碼備有詳盡的注釋便于理解,需要的朋友可以參考下2016-02-02
菜鳥(niǎo)蔡之Ajax復(fù)習(xí)第二篇(JQuery中的load()方法實(shí)現(xiàn)Ajax功能)
在上一篇博客中寫(xiě)到的是在傳統(tǒng)的Javascript中使用XMLHttpRequest對(duì)象異步加載數(shù)據(jù)的,唉,童鞋.......看到那些代碼是不是有點(diǎn)頭疼啊!呵呵......2012-11-11
Ajax動(dòng)態(tài)為下拉列表添加數(shù)據(jù)的實(shí)現(xiàn)方法
這篇文章主要介紹了Ajax動(dòng)態(tài)為下拉列表添加數(shù)據(jù)的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-01-01
淺析Ajax后臺(tái)success傳來(lái)json數(shù)據(jù)的問(wèn)題
最近在使用JQuery的ajax方法時(shí),需要返回的數(shù)據(jù)為json數(shù)據(jù),在success返回中數(shù)據(jù)處理會(huì)根據(jù)返回方式不同會(huì)采用不同的方式來(lái)生成json數(shù)據(jù)。下面小編給大家介紹下在$.ajax方法中應(yīng)該是如何來(lái)處理的2016-10-10
ajax跨域訪問(wèn)報(bào)錯(cuò)501的解決方法
這篇文章主要為大家詳細(xì)介紹了ajax跨域訪問(wèn)報(bào)錯(cuò)501的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
AJax與Jsonp跨域訪問(wèn)問(wèn)題小結(jié)
本文給大家匯總介紹了JavaScript的AJax,JQuery的AJax以及利用jsonp實(shí)現(xiàn)跨域訪問(wèn)的問(wèn)題,非常的細(xì)致全面,有需要的小伙伴可以參考下。2015-12-12

