Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

How does dojo/request handle html/javascript response?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...