4

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(); } }); } 
1
  • I don't think you will have a problem with this. The way it is coded, only one request will be active at a time. Commented Apr 12, 2012 at 19:43

1 Answer 1

1

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!).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.