Alright so what I want is to start looping an ajax call once I press a button, the ajax will communitcate with the database and depending on the response, I want it to either loop, and re-do the exact same call, or stop the call and go to another function.
I have the following code right now:
function checkResult(session, ip, key){
$.ajax({
url: "myUrl"+key,
}).success(function(returnData){
returnData = returnData.replace("\n", "");
returnData = returnData.replace(" ", "");
if(returnData == 1){//Everything is fine, stop the call
clearInterval(interval);
console.log("completed");
}else if(returnData == 2){//Something went wrong, stop the call
clearInterval(interval);
console.log("Something went wrong");
}else if(returnData == 0){//No result found, repeat call
console.log("Nothing was found");
return returnData;
}
});
}
function repeatCall(session, ip, key){
console.log("Repeating the request");
interval = setInterval(function(){ var status = checkPayment(session, ip, key); if(status != 0){
clearInterval(interval);
checkResult(status)}}, 1000);
}
It's currently looping through the whole call only once, it logs "Nothing was found" in my console. What's the correct way of getting this to work???