如何设置缓存:jQuery.get调用中为false [英] How to set cache: false in jQuery.get call

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

问题描述

jQuery.get()jQuery.ajax()的简写,带有get调用.但是,当我在.get()调用的数据中设置cache:false时,发送到服务器的是一个名为cache的参数,值为false.我的目的是将带有数据的时间戳发送到服务器以防止缓存,这是如果我在jQuery.ajax数据中使用cache: false会发生的情况.我如何做到这一点而无需将我的jQuery.get调用重写为jQuery.ajax调用或使用

jQuery.get() is a shorthand for jQuery.ajax() with a get call. But when I set cache:false in the data of the .get() call, what is sent to the server is a parameter called cache with a value of false. While my intention is to send a timestamp with the data to the server to prevent caching which is what happens if I use cache: false in jQuery.ajax data. How do I accomplish this without rewriting my jQuery.get calls to jQuery.ajax calls or using

$.ajaxSetup({
    // Disable caching of AJAX responses
    cache: false
});

更新:谢谢大家的回答.你们都是正确的.但是,我希望有一种方法可以让get调用知道您不想缓存,或者将该值发送到基础.ajax()以便知道如何处理.

update: Thanks everyone for the answers. You are all correct. However, I was hoping that there was a way to let the get call know that you do not want to cache, or send that value to the underlying .ajax() so it would know what to do with it.

我寻找到目前为止已经确定的三种方法之外的第四种方法:

I a. looking for a fourth way other than the three ways that have been identified so far:

  1. 通过ajaxSetup全局进行

  1. Doing it globally via ajaxSetup

使用.ajax调用代替.get调用

Using a .ajax call instead of a .get call

通过在.get调用中添加一个带有时间戳的新参数来手动执行此操作.

Doing it manually by adding a new parameter holding a timestamp to your .get call.

我只是认为应该将此功能内置到.get调用中.

I just thought that this capability should be built into the .get call.

推荐答案

对我来说,正确的方法是列出的方法. ajaxajaxSetup.如果您确实要使用get而不使用ajaxSetup,则可以创建自己的参数,并为其指定当前日期/时间的值.

To me, the correct way of doing it would be the ones listed. Either ajax or ajaxSetup. If you really want to use get and not use ajaxSetup then you could create your own parameter and give it the value of the the current date/time.

但是我会质疑您不使用其他方法之一的动机.

I would however question your motives in not using one of the other methods.

这篇关于如何设置缓存:jQuery.get调用中为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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