问题
I'm trying to execute next:
$.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?
回答1:
In short, set cache to true in your $.ajax call's options.
jQuery adds that for cache breaking.
There is an option in jQuery to turn that off: (from http://api.jquery.com/jQuery.ajax/)
cacheDefault:
true,falsefor dataType 'script' and 'jsonp'If set to
false, it will force requested pages not to be cached by the browser. Setting cache tofalsealso appends a query string parameter, "_=[TIMESTAMP]", to the URL.
Example with cache set to true:
$.ajax({
type: 'GET',
cache: true,
url: 'http://127.0.0.1:6789/dir',
data: "",
success: function (data) { /*do something*/
},
dataType: 'html'
});
回答2:
Check jQuery.ajax documentation
If you look at cache parameter, you can see that it is adding a timestamp at the end of call in that format. If you want to get rid of it try to set cache to true, or type to POST(in case you dont want to allow cashing)
回答3:
I had ajaxSetup attribute in my code:
$.ajaxSetup({ cache: false });
I commented it and it works now! Thanks.
来源:https://stackoverflow.com/questions/10425215/ajax-get-request-with-useless-parameter