I need to have control of the number of concurrent asynchronous calls from ajax, but I can not overwrite the control variable that holds the number of calls. Every time an asynchronous call is launched it uses the value of the first call ( a copy of the variable before the first call I believe)
Follow my code:
var loaderCallStack = [];
var IsLoaderForSubmit = false;
$(document).ready(function() {
$('a[href="' + window.location.hash + '"]').trigger('click');
IsLoaderForSubmit = false;
$(document).ajaxStart(function() {
loaderCallStack.push("handle");
if (IsLoaderForSubmit)
{
//váriaveis que preciso alterar aqui
}
});
$(document).ajaxComplete(function() {
loaderCallStack.pop();
if (IsLoaderForSubmit && (loaderCallStack.length === 0))
{
//váriaveis que preciso alterar aqui
IsLoaderForSubmit = false;
}
});
});
My question is, can I control the number of calls while maintaining the asynchronous code? I know that putting it as synchronous would be an option, but at the moment it is not what is desired.
The solution I thought was to stack something every time the call is made and unpack when it's done. If that happens with a control variable this can not be done, is there another way?