this might have been discussed previously but i didn't find any proper or working answer. i want a generic ajax loader that shows loader gif/animation on every ajax call. now the issue is that if two ajax requests were made at the same time (in real scenario there might be dozen ajax calls running simultaneously)if first ajax request completes first it will close the loading gif but second request is still running.. is there any way i can make sure in generic ajax function that only close the loader gif/animation if there's currently no ajax request processing?
function CallMethod(url, parameters, successCallback) {
//show loading... image
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(parameters),
contentType: 'application/json;',
dataType: 'json',
success: successCallback,
error: function(xhr, textStatus, errorThrown) {
console.log('error');
}
});
}
CallMethod(url, pars, onSuccess);
function onSuccess(param) {
//remove loading... image
//do something with the response
}
this is the code i have seen here already on this link jquery - creating a generic ajax function