I would like to intercept all dojo.xhr
calls on my application in a way to examine the contents of HTTP response before this response gets forwarded to handler functions (load
, error
, etc.). How do you suggest to do this?

- 5,757
- 22
- 73
- 103
2 Answers
I believe what you're looking for is the djConfig variable ioPublish
introduced in 1.4.
http://dojotoolkit.org/reference-guide/releasenotes/1.4.html#io-pipeline-topics
This hooks up three publish topics you can subscribe to: /dojo/io/load
, /dojo/io/error
, and /dojo/io/done
, which should be analogous to the load
, error
, and handle
callbacks, respectively.
Do keep in mind that this is turned off by default precisely because of potential overhead incurred by publishing events on every XHR performed.

- 10,559
- 2
- 23
- 40
-
Never heard of them. They look quite useful. – Shailesh Kumar May 24 '11 at 16:33
Look at Example 9 in the Dojo documentation. What you're looking for is the 'handle' callback method. This is called regardless of whether or not the call is successful, and you can use it to display the data in the response if that is what you are looking to do.
Having answered your question, I noticed some of the examples on the Dojo page are broken. This isn't a good sign for this library's future support. This is the Dojo website after all! It's not just some yahoo's blog that he/she never updates. Additionally, this Google Insights Search on JQuery and Dojo make it pretty clear that JQuery is gaining marketshare in the community while Dojo is floundering.
Unless there is some compelling reason to continue to use Dojo, such as the Comet features, I suggest anyone struggling with the decision of which library to use to just pick JQuery, the clear winner.

- 33,636
- 11
- 99
- 120
-
Thanks for the feedback. In fact, I would like to have a "proxy" standing in between. This proxy function would examine the contents of the response (status code and response body). If there is an error (such as the user not being authorized anymore), raise a popup and disallow the callbacks (`load`, `error`) to be called. If everything is OK, allow callbacks to be called. – Ariod Jan 24 '11 at 13:04
-
Not sure that's possible. The documentation shows your handlers, the handlers will have to act as your proxy where you check in them for things like authorization and then forward onto your success function. – jamesmortensen Jan 25 '11 at 03:36