If your ajax call is asynchronous, you will not end the stack space because sendXHR() returns immediately after sending the ajax request. The callback is then called some time after receiving the ajax response. No stacking.
If your ajax call is synchronous and you want to allow other events and that won't happen in the javascript environment, then you can do something like this:
function sendXHR(url, callback) { // Send XMLHttpRequest to server and call callback when response is received } function infinite() { sendXHR('url/path'); setTimeout(infinite, 1); } infinite();
source share