我在移動應用程序結束後要求之一,我使用多個Ajax調用以接收來自Web服務器的數據像下面jQuery的如何使用多個AJAX的其他
function get_json() {
$(document).ready(function() {
$.ajax({
url: 'http://www.xxxxxxxxxxxxx',
data: {
name: 'xxxxxx'
},
dataType: 'jsonp',
//jsonp: 'callback',
//jsonpCallback: 'jsonpCallback',
success: function(data) {
$.each(data.posts, function(i, post) {
$.mobile.notesdb.transaction(function(t) {
t.executeSql('INSERT into bill (barcode, buildingcode, buildingaddress, flatname, flatdescription, entryseason, period, amount, pastpayments, todaypayments, paydate, receiptno) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);', [post.Id, post.Code, post.Address, post.Name, post.Description, post.EntrySeason, post.Period, post.Revenue, post.PastPayments, post.todaypayments, post.paydate, post.receiptno],
//$.mobile.changePage('#page3', 'slide', false, true),
null);
});
$('#mycontent').append(post.Name);
});
}
});
$.ajax({
xxxx
});
$.ajax({
xxxx
});
});
}
我怎樣才能迫使第二阿賈克斯打電話在第一個結束後開始......第二個結束後的第三個開始,繼續進行下去?
關於這一點的唯一情況是失敗的AJAX調用將導致沒有其他AJAX調用被創建(因爲沒有「如果AJAX調用失敗會這樣做」,它只會永遠等待「成功」)。也許這正是你想要的......只是需要考慮的事情。 – 2012-02-10 22:04:33
我認爲你應該使用$ .when作爲@Lyon的建議。 – 2014-05-06 16:29:53