多个异步ajax请求如何指定顺序执行,急!!!! js异步ajax顺序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用同步的.ajax({ url: url, type : "get",async:false, dataType:'jsonp', jsonp:"jsonpCallback", success: function(result) { //parse result , logic //logicFun(result , index ); console.log('rendering - '+index); } 本人需求明确不能同步,同步就不必这么调用ajax了 看下这个http://www.jb51.net/shouce/jquery1.82/jQuery.when.htmlhttp://www.cnblogs.com/charling/p/3411385.html 自己写代码来控制执行循序,而不是直接for,each并发执行,做递归调用 function loads() { var initPath = 'http://192.168.81.177:8089/di-data-service/'; var reports = ['cpu_report', 'mem_report', 'load_report', 'network_report']; var currentPath = initPath + 'r=day&json=1&cName='; rendering(currentPath, 0, reports); /* $.each(reports, function (index, report) { rendering(currentPath + report, index); })*/ } function rendering(currentpath, index,reports) { $.ajax({ url: currentpath + reports[index], type: "get", dataType: 'jsonp', jsonp: "jsonpCallback", success: function (result) { //parse result , logic //logicFun(result , index ); console.log('rendering - ' + index); index++; if (index < reports.length) rendering(currentpath, index, reports); } }); } function logicFun(data, index) { //parse data , logic console.log('logicFun - ' + index); } 将要发送的数据和地址放到一个数组里 每次ajax返回成功pop后递归执行发送方法试试 各位高手帮帮忙啊!js处理简繁体转换的时候,flash显示不正常! 请帮忙看一下这条语句 重复搜索验证问题~求高手算法逻辑 JAVASCRIPT这种情况是怎么回事?是不是有变量有冲突? 简单问题 弹出窗口的url发生变化,新窗口和母窗口的关系 关于鼠标位置 js数组更新问题 Ext中如何为多选框Ext.form.CheckboxGroup重新加载数据 关于框架的控制问题 在有合并单元格的情况下js怎么给table排序 ? 急急急!!!我想取某一坐标的颜色值,js有办法么
.ajax({
url: url,
type : "get",async:false,
dataType:'jsonp',
jsonp:"jsonpCallback",
success: function(result) {
//parse result , logic
//logicFun(result , index );
console.log('rendering - '+index);
}
本人需求明确不能同步,同步就不必这么调用ajax了
http://www.cnblogs.com/charling/p/3411385.html
var initPath = 'http://192.168.81.177:8089/di-data-service/';
var reports = ['cpu_report', 'mem_report', 'load_report', 'network_report'];
var currentPath = initPath + 'r=day&json=1&cName='; rendering(currentPath, 0, reports);
/*
$.each(reports, function (index, report) {
rendering(currentPath + report, index);
})*/
} function rendering(currentpath, index,reports) {
$.ajax({
url: currentpath + reports[index],
type: "get",
dataType: 'jsonp',
jsonp: "jsonpCallback",
success: function (result) {
//parse result , logic
//logicFun(result , index );
console.log('rendering - ' + index); index++;
if (index < reports.length) rendering(currentpath, index, reports); }
});
} function logicFun(data, index) {
//parse data , logic
console.log('logicFun - ' + index);
}
每次ajax返回成功pop后递归执行发送方法试试