I\'m writing a Tampermonkey script for a web page and trying to extract data from other pages.
I\'m trying to make a function that has a loop inside that goes thru a list, <
Simulate for-loop with async ajax requests. On ajax's complete callback
go to next item in the list:
function F_Company_LLC(llcList) {
var i= 0;
function getNext() {
if(llcList[i][2]=="lab"){
//run function 0
++i;
getNext();
}
else if(llcList[i][2]=="shop"){
//run function 1
++i;
getNext();
}
else{
$.ajax({
url: base_link+"/company/edit_company/"+llcList[i][1], //CompID
method: 'GET',
async: true,
success: function(data) {
if (data.status == "success" && i <= llcList.length) {
//data processing
}
},
error: function(xhr) {
alert("Error while processing CompID: " + llcList[i][1]);
},
complete: function() {
//complete executes after either
//the success or error callback were executed.
++i;
getNext();//go to next item in the list
},
});
}
}
getNext();
}
F_Company_LLC(llcList);