If it is current, will it occurs the problem of call stack overflow?
because it call self infinite recursively
If it will occurs such problem, are there any better implementation?
function waitForMsg(){
$.ajax({
type: "GET",
url: "xxx.php",
async: true,
cache: false,
timeout: 600000,
success: function(data){
handleFunction(data);
waitForMsg();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
XMLHttpRequest.abort();
waitForMsg();
}
});
}
I suppose it’s a kind of recursion, but not strictly in terms of the current context, because you’re adding anonymous functions onto an object that’s passed into the ajax function, and the ajax invocation returns immediately (it doesn’t do anything to evaluate the functions). When the ajax finally succeeds or fails, whichever function needs to be invoked is in a completely new context, with different stack values and stack location.
BTW, I’m not sure I understand the
XMLHttpRequest.abort();invocation. By that time, the XMLHttpRequest has already failed, so abort shouldn’t be necessary (I would think!).