请问jQuery的ajaxSetup({缓存:真})一般工作? [英] Does jQuery ajaxSetup({cache: true}) generally work?

查看:187
本文介绍了请问jQuery的ajaxSetup({缓存:真})一般工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的jQuery 1.4.2省略了时间戳获取参数(击败浏览器cacheing),如果我主张在本地范围内的AJAX缓存设置:

jQuery 1.4.2 omits the timestamp GET parameter (to defeat browser cacheing) if I assert the ajax cache setting in the local context:

$.ajax({
    url: searcher, 
    data: keys,
    cache: true,
    type: 'GET',
    dataType: 'json',
    success: function(data) {
        // something
    });

但它包含时间戳,如果我将设置离开那里,进入全球范围内:

But it includes timestamp if I move the setting out of there and into the global context:

$.ajaxSetup({cache: true});

此外,如果我让默认应用,jQuery的集时间戳,这似乎不符合说明书。

Moreover, if I let the default apply, jQuery sets timestamp, which doesn't seem to match the manual.

你遇到相同的?

你的HTTP缓存服务器控件响应头影响这个jQuery的功能?

Do HTTP cache control response headers from the server affect this jQuery feature?

推荐答案

看起来像它的工作原理。 只有以下三个AJAX调用传递一个时间戳在第二情况的参数。时间戳参数的名称不是时间戳,而是一个下划线。

Looks like it works. The following three ajax calls only passes a timestamp as a parameter in the 2nd case. The name of the timestamp parameter is not timestamp, but rather an underscore.

    $.ajax({ url: '/?=testDefault',
    data: { 'cache': 'default' }
    });//no timestamp

    $.ajaxSetup({ cache: false });
    $.ajax({ url: '/?=testFalse/',
    data: { 'cache': 'false' }
    });//yes, a timestamp

    $.ajaxSetup({ cache: true });
    $.ajax({ url: '/?=testTrue/',
    data: { 'cache': 'true' }
    }); //no timestamp

顺便说一句,你使用的是自动完成插件?这传递一个时间戳默认参数。您可以使用extraParams选项通过传递这样的覆盖它。

As an aside, are you using an autocomplete plugin? That passes a timestamp parameter by default. You can override it using the extraParams option by passing something like this.

extaParams: {timestamp:'cache'}

这篇关于请问jQuery的ajaxSetup({缓存:真})一般工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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