Regular web requests and Ajax requests with dojo.xhrGet/Post are much alike. Both use URL's and both use the HTTP protocol. But with browser requests, it is always clear to user when something goes wrong. You may get a 404 - Page Not Found, or a Server Unavailable, or at least something that says "Error". Ajax requests happen in the background, so when they error out the user won't know. Even worse, if the response never comes the browser may appear to lock up.
That's why it's extremely important to provide an error handler and a timeout handler with any dojo.xhrGet/Post calls. You should consider these as critical as URL or the load function
At the very least, you should alert the user that something went wrong. Here's an example:
dojo.xhrGet({
url: "/cgi-bin/timeout.cgi",
load: function(data){
document.myForm.myBox.value = data;
dojo.byId("boxLoadTime").innerHTML = new Date();
},
error: function(err){
console.debug("Holy Bomb Box, Batman! An error occurred: ", err);
},
timeout: 2000
});
The error() function takes the same arguments that load() does. But unlike load(), the only useful parameter is data, which contains the error message. You can also find out what kind of error was generated by looking at the error object's "dojoType" property. It will usually be "timeout" or "cancel", but other error types are possible.
The timeout, given in milliseconds, defaults to 0, which means "wait forever". Even if you expect the request will take a long time, you should set a high value here (e.g. 15000 = 15 seconds), not 0.