Dojo Goodness, Part 5 (Simple Network I/O)

Matthew Russel post the next article in his series about Dojo. This time he shows how to work with Dojo Input\Output System. Here's one of the examples from this article:

JavaScript

// save the Deferred that is returned from the call

var d = dojo.xhrGet({

url : "localresource.json",

handleAs : "json",

load : function(response, ioArgs) {

/* Handle a successful callback here */

return response;

},

error : function(response, ioArgs) {

/* Handle any errors that occur here */

return response;

}

});

// arbitrarily add callbacks and errbacks to the Deferred...

// we have no idea about its exact execution state right now

d.addCallback(function(response) {

/* Do something after the initial load callback finishes... */

return response;

});

d.addCallback(function(response) {

/* ...and then do something else. */

return response;

});

d.addErrback(function(response) {

/* But if there's an error, do this after the initial error handler finishes */

return response;

});

You can read the full version of this article on the ONLamp site.