jquery queue ajax,如何通过jQuery和Queue发送ajax请求?
嗯,我有一個“ID”列表,我需要為每個“ID”發送一個Ajax請求。 IDE是當請求完成時,運行以下Ajax請求。 所有這些與異步請求,因為否則,瀏覽器字面上“停止”,直到請求完成加載。如何通過jQuery和Queue發送ajax請求?
邏輯很簡單: 我們在循環中創建一個循環,并為每個ID創建一個asinconica的Ajax請求。 問題是,異步Ajax請求阻止我訪問全局變量ID。
例子:
// This list will always have 40 items/values.
var ids = [12,3453,234,743,235,433, ..];
for (var index = 0; index < ids.length; index++) {
// This request take long time(40-60 seconds)
$.ajax({
url : 'http://website.com/id=' + ids[index], // See here how to call to global variable ids
success : function (response) {
// And here, i call the element '#element' and get and set the 'value text'
var currentTotal = parseInt($('#element').text());
$'#element').text(currentTotal + response.total);
},
async:true // See here, this is a Async request
});
}
注意,每個請求都必須以前加載完成后發送,將永遠是一個動態的名單,因為有時我會送不同的ID。
總結
以上是生活随笔為你收集整理的jquery queue ajax,如何通过jQuery和Queue发送ajax请求?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax原理 博客,AJAX工作基本原理
- 下一篇: 服务器和操作系统怎么看,服务器和操作系统