What's the use of jQuery.when?
This article will explain in detail about jQuery.when what is used, Xiaobian thinks it is quite practical, so share it for everyone to make a reference, I hope you can gain something after reading this article.
jQuery.when( deferreds )
Description: Provides a method to execute callback functions for one or more objects, Deferred objects typically representing asynchronous events.
Version added: 1.5jQuery.when(deferees)
deferreds
Type: Deferred
One or more deferred objects, or plain JavaScript objects.
If you pass a deferred object to jQuery.when, its Promise object (a subset of deferred methods) is returned. You can continue to bind other methods of the Promise object, for example, defaulted.then. When a deferred object has been resolved or rejected (usually executed by the original code that created the deferred object), the appropriate callback function is invoked. For example, the jqXHR object returned by jQuery.ajax is a deferred object and can be used as follows:
$.when( $.ajax("test.aspx") ).then(function(data, textStatus, jqXHR){
alert( jqXHR.status ); // alerts 200
});
If a parameter is passed to jQuery.when, it is treated as a resolved deferred object, and any doneCallbacks added to it are executed immediately. What is passed into doneCallbacks is the original argument. In this case, any failbacks set will never be executed because deferred objects will never be rejected. For example:
$.when( { testing: 123 } ).done(
function(x) { alert(x.testing); } /* alerts "123" */
);
About "jQuery.when what is used" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.