如何在ajax请求中控制缓存控制 [英] how to control cache-control in ajax request
问题描述
可能是一个愚蠢的问题,但我搜索了很多没有结果。我知道如何在服务器响应中设置缓存控制,但是如何在ajax请求中更改缓存控制的值?
注意:我希望浏览器使用它的缓存。不希望它从服务器获取更新的json ..这是我要做的全部事情。
might be stupid question but I searched a lot without result. I know how to setup cache-control in server response, but how can I change the value on cache control in ajax request???? NOTE: I want the browser to use it's cache. don't want it to get the updated json from server .. this is the whole thing I'm trying to do.
推荐答案
您可以使用标头
属性,如下所示:
You can use headers
property, like this:
$.ajax({
...
headers: {
'Cache-Control': 'max-age=1000'
}
...
});
请记住缓存
属性没有任何内容与 Cache-Control
标题一样,它只是一个 cache buster (将?_ = {timestamp}
附加到GET参数)并且只能与 GET
和 HEAD
请求。
Keep in mind that cache
property has nothing in common with Cache-Control
header, it's just a cache buster (appending ?_={timestamp}
to GET parameters) and will only work correctly with GET
and HEAD
requests.
无论如何,有用的东西:如何设置HTTP标头(用于缓存控制)?
Anyway, something useful: How to set HTTP headers (for cache-control)?
这篇关于如何在ajax请求中控制缓存控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!