Home >Web Front-end >JS Tutorial >Example sharing of using when in jQuery to implement multiple AJAX requests corresponding to a single callback_jquery
I know that these functions are executed asynchronously (asyncronously) and will return with a delay, so I want to know if there is a way that I can use a single callback to load them in parallel, just like the JS loader curljs does That way. Lucky me! With jQuery.when, I can load two requests concurrently and only execute the callback once!
jQuery Script
As I mentioned, here is a use case for loading a script and a JSON resource:
When the resource loading is completed, the specified done or then callback will be triggered, so you can know that the request has been completed. The type of callback parameter object returned by each request is different, so the above request may return the following information:
If we still need to add a traditional AJAX XHR request, such as a widget template, we can do this:
Dojo Toolkit has had this kind of functionality for a long time, but I’m quite excited that jQuery can do it too. For current development, it is a natural requirement for multiple requests that are not synchronized and whose return order is uncertain to share the same callback, so jQuery is definitely advancing with the times!