Tôi đang ở ứng dụng di động và tôi sử dụng nhiều các cuộc gọi Ajax để nhận dữ liệu từ máy chủ web như dưới đâyjquery làm thế nào để sử dụng nhiều ajax gọi một sau khi kết thúc sự khác
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
});
});
}
Làm thế nào tôi có thể buộc các ajax 2 gọi để bắt đầu sau khi kết thúc đầu tiên ... thứ 3 sau khi kết thúc ngày 2 và tiếp tục?
Điều duy nhất về việc này là cuộc gọi AJAX không thành công sẽ không dẫn đến các cuộc gọi AJAX khác (vì không có "thực hiện điều này nếu cuộc gọi AJAX không thành công", nó sẽ chờ một "thành công" mãi mãi). Có lẽ đó là chính xác những gì bạn muốn ... chỉ cần một cái gì đó để xem xét. –
Tôi nghĩ bạn nên sử dụng $ .when như @Lyon gợi ý. –