Dojo - intercepting XHR calls

妖精的绣舞 提交于 2019-12-08 10:30:20

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4781018/dojo-intercepting-xhr-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!