【问题标题】:JqueryMobile Cache Ajax issueJqueryMobile 缓存 Ajax 问题
【发布时间】:2012-09-10 09:35:02
【问题描述】:

我的 jquery 移动应用程序有一个奇怪的问题。下面是 Chrome 开发者工具快照的屏幕截图。

为什么我的页面或脚本即使添加了也会被缓存

 $.ajaxSetup ({
            cache: false
        });

在每个加载我的ul > li 的 ajax 调用中也设置了cache:false

请告诉我如何克服这种情况,因为我的移动缓存在每次点击时都会增长,让我发疯。

谢谢

更新

每次我点击导航到另一个页面时,这个脚本都会被执行:

$('body').on('click', '.menuClass', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var menuid = $(this).attr('id');
if (menuid == '100001') {
    settings.get('setval', function(obj) {
        if(obj.value.tableMode == "1"){
        $.mobile.changePage('categories.html', {
            transition : "slide"
        });
        return false;
        }
        else{
         $.mobile.changePage('index.html', {
                        transition : "slide"
                    });
        }
     });
   }
 });

但由于某些原因,category.html 的 URL 会在每次点击时加载,将 URL 更改为 下面

   http://localhost:8080/categories?_=1347279588477
   http://localhost:8080/categories?_=1347279584203
   http://localhost:8080/categories?_=1347279688227

【问题讨论】:

    标签: html jquery jquery-mobile browser-cache


    【解决方案1】:

    我不知道为什么 cache:false 不起作用,但我添加了一个时间创建的字符串来防止 ajax 页面的缓存。

    通过在 url 末尾添加 &ts="+ new Date().getTime() 来做到这一点。

    这是我的用法;

    $.ajax({
           type: "GET",
           url: "ajax.php?ajax_file=ajax_table_page&ts="+ new Date().getTime(),
           success: function(data){
           ..................
           }
    });
    

    我也用它来跟踪 ajax 错误(你可以在文档准备好后添加)

    $.ajaxSetup({
      error:function(x,e){
           if(x.status==0){
           alert('You are offline!!\n Please Check Your Network.');
           }else if(x.status==404){
           alert('Requested URL not found.');
           }else if(x.status==500){
           alert('Internel Server Error.');
           }else if(e=='parsererror'){
           alert('Error.\nParsing JSON Request failed.');
           }else if(e=='timeout'){
           alert('Request Time out.');
           }else {
           alert('Unknow Error.\n'+x.responseText);
           }
      }
      });
    

    【讨论】:

    • 您好,谢谢,在我的情况下它不起作用。在我的pageshow 上加载 ajax 调用有什么影响吗?
    猜你喜欢
    • 2013-02-18
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 2011-05-22
    • 2015-03-02
    相关资源
    最近更新 更多