Mootools 请求更改 JavaScript 代码?
因此,我计划通过从另一个页面获取页面的内容来动态更改页面的内容。
为此,我使用了 Mootools 的 Request 类:
var tabContent = new Request({
url: 'foo/bar/baz.php',
onSuccess: function(data) {
$('tab_container').innerHTML = data;
}
}).send();
在任何情况下,HTML 都能正常获取,并且顺利返回。但是,我想向那些获取的元素(准确地说是 Fx.slide)添加一些事件,这需要在请求的文件中包含一些 js。
检查返回的数据后,javascript 完好无损。然而,它并没有出现在最终产品中。也就是说,在接收数据和渲染数据(通过innerHTML 位)之间的某个地方,似乎 javascript 由于某种原因已被删除。
嗯。
So I am planning on dynamically changing a page's content by fetching it from another page.
To do so, I used Mootools' Request class:
var tabContent = new Request({
url: 'foo/bar/baz.php',
onSuccess: function(data) {
$('tab_container').innerHTML = data;
}
}).send();
In any case, the HTML is fetched fine, and returns without a hitch. However, I'd like to add some events to THOSE fetched elements (Fx.slide, to be precise), and that requires some js to be included in the requested file.
Upon inspection of the returned data, the javascript is intact. However, it does not show up in the final product. That is, somewhere in between having received the data, and rendering the data (via the innerHTML bit) it seems as though the javascript has been excised out for some reason.
Hm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
evalScripts: true
添加到请求选项,然后将脚本包含在响应底部的简单块中。
add
evalScripts: true
to the Request options, then include the script in a simple<script></script>
block at the bottom of the response.