简体   繁体   English

使用JavaScript加载部分内容

[英]Load partial content with javascript

So, now I want to load a page layout and then load the content using AJAX. 因此,现在我想加载页面布局,然后使用AJAX加载内容。 I am using Mootools Request.HTML as it parses the HTML response. 我正在使用Mootools Request.HTML来解析HTML响应。 The thing here is the javascript content in the page, the inline javascript always executes immediately, however, the external javascript is not executed (evaluated). 这里的事情是页面中的javascript内容,内联javascript总是立即执行,但是,外部javascript不执行(评估)。

For the purpose of testing this, I create an inline script which updates a <span> with the current date, then I created an external file with similar contents (this one was to update other <span> ). 为了进行测试,我创建了一个内联脚本,该脚本以当前日期更新<span> ,然后创建了一个内容相似的外部文件(此文件将更新其他<span> )。 This first one (inline) executes as the content is loaded, the second one (external) is not executed. 第一个(内联)在加载内容时执行,第二个(外部)不执行。

For the ones who want to know what I am planing to do with this: I will use the new HTML5 history.pushState + AJAX to load a page partially, in a way it loads faster to the user and relief the server a little bit (as it will provide less requests). 对于那些想知道我打算如何处理的人:我将使用新的HTML5 history.pushState + AJAX来部分加载页面,以一种更快的速度向用户加载并减轻服务器负担(因为它将提供更少的请求)。

Request.HTML has an option: evalScripts and you can choose to evaluate or not evaluate scripts that are included in returned HTML. Request.HTML有一个选项: evalScripts ,您可以选择评估还是不评估返回的HTML中包含的脚本。

So it might be: 因此可能是:

var myHTMLRequest = new Request.HTML({
    url: '/loadMe.html',
    evalScripts: true
}).get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM