0
我正在使用MooTools 1.4。如何在我的頁面上動態添加腳本標記?從下面的阿賈克斯requset的響應應該包含標籤...如何在我的Ajax請求中包含Javascript腳本標記?
window.addEvent('domready', function() {
$('submit').addEvent('click', function(event) {
var filename = $('filename').value;
//prevent the page from changing
event.stop();
//make the ajax call
var req = new Request({
method: 'get',
url: 'renderpage?id=' + escape(filename),
data: { },
evalScripts: true,
onRequest: function() {
// on request
},
onComplete: function(response) {
$('content').set('html',response);
// Add the Ajax call where we save the data.
...
});
}
}).send();
});
});
但是,當我看着響應,之後就被去掉了。我希望他們包括和評估。我怎樣才能做到這一點?
你是如何看的響應?瀏覽器在這種情況下不會去掉'
使用Request.HTML。
來源
2011-10-28 21:29:18 MattiSG
是你不解釋爲什麼downvote ?? : -/ – MattiSG
+1幾年後...並且您向我提供了一個非常乾淨的解決方案!謝謝,這應該是upvoted更多,是被接受的答案! – Shautieh
傳遞給
onComplete
的參數是:nodeTree, xhr, responseHTML, responseScripts
所以:
來源
2012-07-09 14:41:28
爲什麼'eval'他們?閱讀[HTML.Request文檔](http://mootools.net/docs/core/Request/Request.HTML):_「evalScripts - (布爾:默認爲true)如果設置爲true,腳本標籤內的響應將被評估。這覆蓋了來自Request的虛假默認值。「_ – MattiSG