Multiple AJAX Calls in YUI 3
Although my preferred JavaScript framework is jQuery, I’ve been using YUI 3 professionally quite a bit in the last months. Recently, I had the need to handle multiple concurrent AJAX calls and bind them to their own event handlers. This can be accomplished with:
Y.io('url',
{
on: {success: callbackFunction}
});
As documented in the jQuery-YUI 3 Rosetta Stone, a useful tool for jQuery developers looking for equivalent functionality in YUI 3.
The YUI 3 AJAX documentation (or “IO” module), includes only how to handle all AJAX complete events, as follows:
Y.on('io:complete', callbackFunction);
var request = Y.io(url);
I have not tried yet, but the following might also work to handle a specific request’s success/complete events, similar to the first block of code:
var request = Y.io(url);
request.on('complete', callbackFunction);
Note: Use the complete event to handle all server responses, and the success event to handle 2xx (success) responses, as noted in the YUI 3 IO API.