2012-08-15 71 views
2

我想在加载脚本时禁用时间戳。请参阅图像使用时间戳禁用加载脚本

enter image description here

http://dl.dropbox.com/u/19616542/Capture.PNG

我还设置了AJAX,缓存:真。下面是代码:

$.ajax({ 
      url:url 
      data:{}, 
      type:'post', 
      cache: true, 
      dataType:'json', 
      success:function(data,status){ 
//something here 

      } 
      else { 
       window.location.reload(); 
      } 
      } 
}); 

,也是我有

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<meta http-equiv="Pragma" content="Public"> 
<meta http-equiv="Cache-control" content="public"> 
<meta name="keywords" content="something"> 
<meta http-equiv="Content-Style-Type" content="text/css"> 
<meta http-equiv="Content-Script-Type" content="text/javascript"> 

我使用jQuery.1.7.2

+0

这些都是为'GET'但你上面有'POST' – Musa 2012-08-15 00:44:02

+0

这样就意味着我需要做的POST所有的Ajax? – Sml004 2012-08-15 00:48:25

+0

但看看第一行,我只是加载jQuery。但为什么它有时间戳? – Sml004 2012-08-15 00:49:26

回答

3

我不确定为什么jQuery试图加载自己,但是这似乎与$.getScript()调用有关。

你可以考虑添加以下代码段为高达越好:

$.ajaxSetup({ 
    cache: true 
}); 

cache: true$.ajax()不以任何方式影响$.getScript(),这就是你在截图看到的。

+0

我应该把这个放在哪里? $ .ajaxSetup({cache:true }); 因为我已经把ajax函数中的cache:true。 – Sml004 2012-08-15 01:08:30

+0

@ Sml004你应该把它放在你的HTML中的

1

我不知道很多关于笨直接在HTML的标题,但它应该和CakePHP一样。你应该有一个类似config的文件名或类似的文件名,它包含一个调试级别。当它设置为调试mod时,它可能会自动为脚本添加时间戳并处理堆栈的错误不同

+0

是的,我将它设置为4级,它将记录所有错误。但当我禁用它(设置为0),我仍然得到时间戳。 – Sml004 2012-08-15 01:00:56

+0

应该有另一个变量!我目前正在查看codeIgniter代码来尝试找到它。在cake中,有一个名为asset.timestamp的变量,我可以将它设置为true或false(并且也可以将它与调试级别相链接)。代码点火器应该有类似的东西! – 2012-08-15 01:04:08

+0

你用什么codeIgniter函数来加载脚本?你只是加载他们的HTML字符串,或者你加载他们的功能? – 2012-08-15 01:18:23

1

$.ajaxPrefilter('script', function(options) { 
    options.cache = true; 
}); 

// or 

+ function($) { 
    $.cachedScript = function(url, options) { 
     // Allow user to set any option except for dataType, cache, and url 
     options = $.extend(options || {}, { 
      dataType: "script", 
      cache: true, 
      url: url 
     }); 

     // Use $.ajax() since it is more flexible than $.getScript 
     // Return the jqXHR object so we can chain callbacks 
     return $.ajax(options); 
    }; 
}(jQuery); 

// now, you can use $.cachedScript() 

你可以去查看文档$.getScript()