How does dojo/request handle html/javascript response?

那年仲夏 提交于 2019-12-13 09:16:17

问题


Actually, we know dojo/request have a property "handleAs" that can handle about:

  • text
  • json
  • javascript
  • xml

But how about if the response is a html fragment with javascript embedded? How to handle it?

I am having this problem quite while, I tried to use handleAs: html. The html rendering fine, but I never get the javascript works.


回答1:


As I explained you in your other questions, JavaScript is never automatically being executed when using AJAX requests (like dojo/request/xhr) out of security matters.

If you want to execute JavaScript code that's dynamically loaded, you will have to use the eval() function to parse it. However, I also told you already that the Dojo toolkit already has a module to handle XHR requests and execute scripts on it by using a dojox/layout/ContentPane and the executeScripts property.

However, the use of eval() and loading scripts from an AJAX request is considered a bad practice and means your application design probably could be improved. Move the JavaScript onto the parent page (in stead of the fragments) and then you have no problems.



来源:https://stackoverflow.com/questions/23720344/how-does-dojo-request-handle-html-javascript-response

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