我需要等到三个ajax调用完成,直到另一个函数开始.我已尝试使用jquery延迟承诺https://api.jquery.com/deferred.promise/但我的作业在加载延迟数据之前返回.我需要在激活函数之前强制完成这三个ajax调用.我没有被限制使用延迟,这似乎是合乎逻辑的方式.
我正在使用数据表,并且在将数据加载到数据表之前需要完成ajax调用.
"ajax":{
"url": API_ROOT + "jobs?available=true&max_results=500",
"dataSrc": function(data){
function all_loaded(){
var dfd = $.Deferred();
var mats_loaded, fins_loaded, pros_loaded;
setTimeout(function(){
$.ajax({
url: API_ROOT + "finishes?max_results=500",
dataType: 'json',
error: function(){
console.log("Error getting finishes");
},
success: function(data){
finishes = data._items;
fins_loaded = true;
check_all_loaded();
}
});
},2000);
?
$.ajax({
url: API_ROOT + "processes?max_results=500",
dataType: 'json',
error: function(){
console.error("Error getting processes");
},
success: function(data){
processes = data._items;
pros_loaded = true;
check_all_loaded();
}
});
?
$.ajax({
url: API_ROOT + "materials?max_results=500",
dataType: 'json', …Run Code Online (Sandbox Code Playgroud)