Error handler being wrongly invoked in callback to dojo.io.bind

I’ve seen behaviour when using Dojo‘s ajax request handler dojo.io.bind where a valid response is returned, but it’s error handler is called. This seemed to be an error on Dojo’s part, as all the headers were correct (set to 200 and the correct content type, “text/plain”), but after much frustration, I stumbled on the answer – the load method was being called, but an exception was being thrown. The Dojo code seems to wrap the load method in a try/catch block, and if an exception is thrown, the error function is then called.

So, if you see you error functions being called when they shouldn’t be, stick a try/catch block inside your load function to see if that’s the problem.