如何动态加载gwt生成的nocache.js文件? [英] How to dynamically load a gwt generated nocache.js file?

查看:264
本文介绍了如何动态加载gwt生成的nocache.js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用JQuery来动态加载GWT生成的 foo / foo / nocache.js 文件。 SomeHow foo / foo / nocache.js 文件不会被浏览器执行。如果我通过使用JQuery使用GWT风格并使用Jut来放置脚本,那么在页面加载后,它将动态生成一个脚本(即..,jquery.onInjectDone('jquery'))。现在,如果我使用JQuery或javaScript创建脚本标记,那么它不会生成动态生成的脚本。



现在我怎样才能确保 foo /foo/nocache.js 使用jQuery执行?



代码:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd> 
<%@ page contentType =text / html; charset = UTF-8language =javaisELIgnored =false%>
< html>
< head>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\">
< / script>
< script>
$(document).ready(function(){
$(#clickMe)。click(function(){
//这是/foo/foo.nocache.js这是生成的GWT编译器。
$ .getScript(/ foo / foo.nocache.js,function(data,textStatus,jqxhr){
console.log(data); //数据返回
console.log(textStatus); // success
console.log(jqxhr.status); // 200
console.log('Load was performed。');
}) ;
});
});
< / script>
< / head>
< body>
< h1> Web应用程序入门项目< / h1>
< a href =#id =clickMe> clickMe< / a>
< div id =name>
< / div>
< / body>
< / html>

输出:


ReferenceError:foo未定义


解决方案

根据您使用的链接器,在文档创建完成后,您无法加载 .nocache.js 脚本,因为它使用 document.write (请参阅 IFrameTemplate.js#344 XSTemplate.js#279 )。这会使您页面中当前的所有内容都被覆盖。否则,如果选择 xsiframe 链接器,则可以加载脚本,但可以使用它用于计算的算法该排列是,使用脚本标记或文档的位置,因此无法使用ajax加载它,但会插入脚本标记。

  $(#clickMe)。click(function(){
$('body')。append($(< script src = foo / foo.nocache.js />)) ;
}


I would like to load a GWT generated foo/foo/nocache.js file dynamically by using JQuery. SomeHow this foo/foo/nocache.js file is not executed by the browser. If I put the script normally by using GWT style withOut using the JQuery, then after the page is loaded it is generating a script(ie.., jquery.onInjectDone('jquery') ) dynamically. Now if I create this script tag using JQuery or javaScript then it is not generating the dynamically generated script.

Now how can I make sure that foo/foo/nocache.js is executed using jQuery?

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
 <head>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
   </script>
  <script>
   $(document).ready(function() {
   $("#clickMe").click(function() {
   // This /foo/foo.nocache.js which is generated by GWT compiler.
       $.getScript("/foo/foo.nocache.js", function(data, textStatus, jqxhr) {
           console.log(data); //data returned
           console.log(textStatus); //success
           console.log(jqxhr.status); //200
           console.log('Load was performed.');
        });
    });
   });
   </script>
 </head>
 <body>
   <h1>Web Application Starter Project</h1>
    <a href="#" id="clickMe">clickMe</a>
    <div id="name">
    </div>      
 </body>
</html>

Output:

ReferenceError: foo is not defined

解决方案

Depending on the linker you are using, you could not load the .nocache.js script after the document creation has been finished because it loads the appropriate permutation by using document.write (see IFrameTemplate.js#344 and XSTemplate.js#279 ). This makes that all your current content in your page would be overwritten.

Otherwise, If you select xsiframe linker, you can load the script, but the algorithm it uses to compute where the permutation is, uses the script tag or the location of your document, so you cannot load it using ajax but inserting a script tags.

$("#clickMe").click(function() {
  $('body').append($("<script src=foo/foo.nocache.js />")); 
}

这篇关于如何动态加载gwt生成的nocache.js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆