jQuery如何禁用AJAX缓存? [英] How does jQuery disable AJAX caching?

查看:251
本文介绍了jQuery如何禁用AJAX缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要禁用来自ajax请求的缓存文件,可以使用jQuery的

To disable caching files from ajax requests, you can use jQuery's

$.ajaxSetup({
    cache: false
});

但是jQuery如何做到这一点?我知道jQuery是一个javascript库,因此使用jQuery可以完成的任何操作都可以使用普通javascript来完成.所以我的问题是: jQuery用来关闭ajax文件缓存的javascript代码是什么?

But how does jQuery do this? I know jQuery is a javascript library, so whatever can be done with jQuery can be done with plain javascript. So my question is: What is the javascript code that jQuery uses under the hood to turn off ajax file caching?

推荐答案

这是缓存的来源

        if ( s.cache === false ) {
            s.url = rts.test( cacheURL ) ?

                // If there is already a '_' parameter, set its value
                cacheURL.replace( rts, "$1_=" + nonce++ ) :

                // Otherwise add one to the end
                cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
        }

s是ajax的选项, 如果您将cache设置为false,它将在您的请求url中添加搜索, 'nonce'是jQuery.now(),是时候了; 因此,当您发送ajax时,浏览器将不会缓存用户,请求的URL总是与众不同.

s is ajax's option, If you set cache false, It will add a search to you request url, The 'nonce' is jQuery.now(), It's a time; So browser will not user cache when you send ajax , request url always differenrt.

这篇关于jQuery如何禁用AJAX缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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