2015-12-14 32 views
0

我使用离线机架离线方法,但在我的一个js文件中,我需要避免缓存一个ajax调用,因为同样的js用于离线和在线。但在页面重新加载时使用相同的缓存联机时?有没有其他方法可以避免缓存?阿贾克斯与离线缓存

$('#cSearch').keyup(function(e){ 
    var number = $(this).val(); 
    var urlVal = "/customer/get_details"; 
    $.ajax({ 
     cache: false, 
     url: urlVal, 
     data: {"term": number, t: Math.random() }, 
     success: function(){ 
     } 
    }); 

}); 

回答

1

您可以使用VAR来检查系统是否已连接到网络:

$('#cSearch').keyup(function(e){ 
    var number = $(this).val(); 
    var urlVal = "/customer/get_details"; 
    var cache = window.navigator.onLine ? false : true; // check if sys is online 
    $.ajax({ 
     cache: cache, // <-----use it here 
     url: urlVal, 
     data: {"term": number, t: Math.random() }, 
     success: function(){ 
     } 
    }); 
}); 
+0

感谢您的答复@jai,但这里的问题是,即使高速缓存是假的,它从缓存中取出,不会调用rails方法。此外,我试图添加时间戳与网址,也无法正常工作。 – amtest

+0

得到了问题,这是请求方法的问题 – amtest