【问题标题】:Unwanted underscore and unix timestamp appearing after javascript includejavascript包含后出现不需要的下划线和unix时间戳
【发布时间】:2013-09-09 23:02:29
【问题描述】:

在使用 jquery 的加载函数加载的页面上,包含的所有 javascript 文件都有一个参数“_”,其值等于当前 unix 时间戳加上加载时的 3 个额外数字。

例如,如果我包含“file.js”,则包含的实际文件将是“file.js?_=1378360893522”。

它阻止了 javascript 文件的缓存,有没有办法阻止这种行为?

编辑:这里要求的是相关代码:

index.html:

<html>
    <head>
        <script type="text/javascript" src="js/jquery.min.js"></script>
    </head>
    <body>
        <div id='new-page'></div>
    </body>
    <script>
        $(document).ready(function() {
            $('#new-page').load("another-page.html");
        });
    </script>
</html>

另一个页面.html:

<html>
    <head>
        <script type="text/javascript" src="js/another-js-file.js"></script>
    </head>
    <body>
    </body>
</html>

“another-js-file.js”加载为“another-js-file.js?_=1378425747710”

第二次编辑:已回答。对于那些阅读本文的人,我将负载调用更改为更像:

$.ajax({
    url: "another-page.html",
    cache: true,
    dataType: "html",
    success: function(data){
        $("#new-page").html(data);
    }
});

有些人说某些插件可能会通过 ajaxSetup 将缓存设置为 false,因此可能需要在要缓存的 ajax 调用之前使用它:

$.ajaxSetup({cache:true});

【问题讨论】:

  • 能贴出相关代码吗?
  • 谢谢,我已更新问题以包含示例。

标签: javascript jquery caching include numbers


【解决方案1】:

您的问题有据可查,可以从以下方面获取解决方案:

jQuery version 1.5 - ajax - <script> tag timestamp problem

解决方案涉及在 jQuery AJAX 调用中使用 cache 选项。

【讨论】:

  • 这行得通,谢谢。我已更新我的问题以包含针对此问题的特定答案。
猜你喜欢
  • 1970-01-01
  • 2018-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-08
  • 1970-01-01
相关资源
最近更新 更多