gpt4 book ai didi

jquery - Ajax请求一步一步

转载 作者:行者123 更新时间:2023-12-01 07:30:35 27 4
gpt4 key购买 nike

我有超过 100 个 ajax 请求,尤其取决于页面上有多少 .miniCanvas 类。我想在收到上一个 ajax 响应时发送下一个 ajax 请求。

这是我的代码:

$def(".miniCanvas").each(
function()
{
getChartData($def(this));
});
function getChartData(me)
{
$def.ajax(
{
url: 'allmoves.php?path=getchart&'+me.attr('id'),
cache: false,
success:function(msg){handleChartData(msg, me)},
error: function(msg){alert('Error loading data.')}
});
}
function handleChartData(data, me)
{
var aData = new Array();
id=me.children('div').attr('id');
var plot1 = $def.jqplot (id, [JSON.parse(data)],
{
series:[{showMarker:false}],
axesDefaults: {
show: false,
showTicks:false
}
});
}

最佳答案

var GetCharData = function() {
var queue = [],
running = false,
next = function() {
running = false;
if (queue.length) GetCharData(queue.shift());
};

return function(me) {
if (running) return queue.push(me);
running = true;
$.ajax({
url: 'allmoves.php?path=getchart&'+me.attr('id'),
cache: false,
success: function(msg) {
// Handle Success
},
error: function(msg) {
// Handle Failure
},
complete: next
});
};
}();

然后

$(".miniCanvas").each(function() { GetCharData($(this)); })

http://jsfiddle.net/robert/EHCW5/

关于jquery - Ajax请求一步一步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524667/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com