dojo /请求如何处理html / javascript响应? [英] How does dojo/request handle html/javascript response?
问题描述
- text
- json
- javascript
- xml
但是如果响应是嵌入JavaScript的HTML片段呢?如何处理?
我有这个问题,而我试图使用句柄:html。
正如我在其他问题中解释的那样,JavaScript是<使用AJAX请求(如 dojo / request / xhr
)时,强制>永不自动执行。
如果要执行动态加载的JavaScript代码,则必须使用 eval()
函数来解析它。但是,我也已经告诉过,Dojo工具包已经有一个模块来处理XHR请求,并通过使用 dojox / layout / ContentPane
和 executeScripts
property。
然而,使用 eval()
和从AJAX请求中加载脚本被认为是不好的做法,意味着您的应用程序设计可能会得到改进。将JavaScript移动到父页面(代替碎片),然后您没有问题。
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.
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.
这篇关于dojo /请求如何处理html / javascript响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!