I'm making in code a few requests with JQuery and get
. It looks like:
$.get('address1', function() { ... });
$.get('address2', function() { ... });
$.get('address3', function() { ... });
// This code should be runned when all 3 requests are finished
alert('Finished');
So, are there any ways to detect whether there is still processing request and run marked code only when all 3 requests are finished.
Thanks.
You can make use of deferred objects [docs] introduced in jQuery 1.5:
$.when(
$.get('address1', function() { ... }),
$.get('address2', function() { ... }),
$.get('address3', function() { ... })
).then(function() {
alert('Finished');
});
Reference: jQuery.when
The jQuery learning center has a nice introduction to deferred objects / promises.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With