Javascript ajax 调用在我的调用末尾添加“?=####”
Javascript ajax call adding "?=####" to the end of my call
我有一个简单的 ajax 命令调用 URL 到我的服务器:
$.ajax({ type: "GET", url: "/action" });
我的日志的响应显示为 /action?_=1423024004825
有没有办法删除这个?
_=#### 是缓存破坏者。当您将缓存设置设置为 false 时,它会将其附加到查询字符串以使其成为新请求,而不是使用响应的缓存版本。
要阻止它被附加,只需将设置更改为 true(现在将使用缓存的响应)
jQuery.ajaxSetup({cache:true});
您还可以通过将缓存设置添加到选项来基于每个请求进行设置
jQuery.ajax({
type: "GET",
url: "/action",
cache:true
});
http://api.jquery.com/jQuery.ajax
cache (default: true, false for dataType 'script' and 'jsonp')
Type: Boolean
If set to false, it will force requested pages not to be
cached by the browser. Note: Setting cache to false will only work
correctly with HEAD and GET requests. It works by appending
"_={timestamp}" to the GET parameters. The parameter is not needed for
other types of requests, except in IE8 when a POST is made to a URL
that has already been requested by a GET.
我有一个简单的 ajax 命令调用 URL 到我的服务器:
$.ajax({ type: "GET", url: "/action" });
我的日志的响应显示为 /action?_=1423024004825
有没有办法删除这个?
_=#### 是缓存破坏者。当您将缓存设置设置为 false 时,它会将其附加到查询字符串以使其成为新请求,而不是使用响应的缓存版本。
要阻止它被附加,只需将设置更改为 true(现在将使用缓存的响应)
jQuery.ajaxSetup({cache:true});
您还可以通过将缓存设置添加到选项来基于每个请求进行设置
jQuery.ajax({
type: "GET",
url: "/action",
cache:true
});
http://api.jquery.com/jQuery.ajax
cache (default: true, false for dataType 'script' and 'jsonp')
Type: Boolean
If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.