jQuery的1.5版本 - AJAX - <脚本>标记时间戳问题 [英] jQuery version 1.5 - ajax - <script> tag timestamp problem

查看:162
本文介绍了jQuery的1.5版本 - AJAX - <脚本>标记时间戳问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我加载使用AJAX(jQuery的)一些内容已在它的脚本标记,jQuery的1.5增加了时间戳script标签的src URL。见例如波纹管。

If I load some content with ajax (jQuery) which has a script tag in it, jQuery 1.5 adds the timestamp to the script tag src url. See example bellow.

例: 内容我加载使用AJAX:

Example: content what I load with ajax:

<div>text1</div>
<script type="text/javascript" src="/js/abc-xyz.js?r=1.1"></script>

这是从它加载脚本code后,我插入了previous内容到页面的src网址:

This is the src url from where it loads the script code after I insert the previous content to the page:

.../js/abc-xyz.js?r=1.1&_=1297892228466

有谁知道为什么会这样呢? 这种事只使用jQuery 1.5。它不会发生与jQuery 1.4.4。

Does anybody knows why this happening? It happens only with jQuery 1.5. It doesn't happen with jQuery 1.4.4.

code例:

$.ajax({
    url: content.html,
    type: 'GET',
    data: someDataObject,
    success: function(data) {
        // some code here

    },
    error: function(data) {
        // some code here
    }
});

感谢。

推荐答案

参见下文是我得到了jQuery开发团队回来的答案。 票务#8298: http://bugs.jquery.com/ticket/8298

See bellow the answer what I got back from jQuery team. Ticket #8298: http://bugs.jquery.com/ticket/8298

答:

检查您的报告,您的code样品后,我得出的结论是,这是不是一个错误。我还做了这个测试用例的jQuery 1.4+(至1.5)有这引起了缓存选项不是一个bug默认为false,脚本的请求。这个bug(见#7578 )已被固定在1.5。 现在,你可能知道或不知道的是,那做jQuery的DOM操作(以prevent某些错误在IE浏览器)时,不特殊处理脚本标记。它过滤出来,并通过AJAX请求它​​们。这就解释了为什么即使是正常的内联脚本标记突然被要求额外的URL参数。 有办法解决这个如果有有害的副作用你。

After checking your report and your code samples I come to the conclusion that this isn't a bug. I also made this test case jQuery 1.4+ (until 1.5) had a bug which caused the cache option not to default to false for script requests. This bug (see #7578) has been fixed in 1.5 . Now what you might know or not know is, that jQuery does special-handle script tags when doing DOM manipulations (to prevent certain errors in IE). It filters them out and requests them via ajax. This explains why even a "normal" inline script tag suddenly is requested with additional url parameters. There are ways to work around this if it has unwanted side effects for you.

  1. 使用$ .ajaxSetup({缓存:真})在适当的时候

  1. use $.ajaxSetup({ cache: true }) when appropriate

使用 prefilter 脚本请求而如检查URL地址不想要 要添加的随机参数,设置高速缓冲存储器:在prefilter对那些真正

use a prefilter for script requests and e.g. check for urls where you don't want the random parameter to be added and set cache: true in the prefilter for those

在如成功的回调处理脚本通过做一些沿着这些路线标签自己 VAR elems = $(htmlwithscripttags); elems.filter(脚本)//现在做任何的脚本 elems.filter(:不是(脚本))appendTo(身体)。 //e.g。

in e.g. the success call back handle the script tags yourself by doing something along these lines var elems = $(htmlwithscripttags); elems.filter("script") //now do whatever with the scripts elems.filter(":not(script)").appendTo("body"); //e.g.

这篇关于jQuery的1.5版本 - AJAX - &LT;脚本&GT;标记时间戳问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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