Ajax获取带有无用参数的请求 [英] Ajax get request with useless parameter
问题描述
我正尝试执行下一个:
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:6789/dir',
data: "",
success: function(data) { /*do something*/ },
dataType: 'html'
});
但是,当它执行时,我的服务器会收到类似以下的内容:
But when it executes, my server receives something like below:
http://127.0.0.1:6789/dir?_32567871112
我不想传递任何参数.我怎么了
I don't want to pass any parameters. What do I wrong?
推荐答案
简而言之,在$.ajax
调用选项中将cache
设置为true
.
In short, set cache
to true
in your $.ajax
call's options.
jQuery将其添加到缓存中.
jQuery adds that for cache breaking.
jQuery中有一个选项可以将其关闭:(来自 http://api.jquery. com/jQuery.ajax/)
There is an option in jQuery to turn that off: (from http://api.jquery.com/jQuery.ajax/)
cache
默认值:true
,false
用于数据类型'script'和'jsonp'
Default: true
, false
for dataType 'script' and 'jsonp'
如果设置为false
,它将强制请求的页面不被缓存
浏览器.将缓存设置为false
还会附加一个查询字符串参数,
网址的网址为"_ = [TIMESTAMP]".
If set to false
, it will force requested pages not to be cached by the
browser. Setting cache to false
also appends a query string parameter,
"_=[TIMESTAMP]", to the URL.
将cache
设置为true
的示例:
$.ajax({
type: 'GET',
cache: true,
url: 'http://127.0.0.1:6789/dir',
data: "",
success: function (data) { /*do something*/
},
dataType: 'html'
});
这篇关于Ajax获取带有无用参数的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!