jQuery .get appends an unknown variable to URL
I'm using this code as the starting point to an overhaul of our JavaScript framework:
$("#get").click(fu开发者_Go百科nction(){
$("#result").html(ajax_load);
$.get(
"http://www.google.com",
{},
function(responseText){
$("#result").html(responseText);
},
"html"
);
});
But when the request is made it includes a variable within the URL that I am unfarmiliar with, here is what Firebug says it's requesting:
http://www.google.com/?_=1268993359215
How do I get rid of this, when we target our internal scripts it's firing a 404 error :-(
Cheers!
That parameter is used to force browser not to use cache.
You can not make $.get
work without it explicitly, but you can use $.ajax
instead:
$("#get").click(function(){
$("#result").html(ajax_load);
$.ajax({
url: "http://www.google.com",
data: {},
success: function(responseText) {
$("#result").html(responseText);
},
cache: true,
dataType: "html"
});
});
Note the extra parameter cache: true
. More on $.ajax
here: http://api.jquery.com/jQuery.ajax/
Try this, before any $.get put this code
$.ajaxSetup({cache:true});
Forcing the browser not to cache the target page is a good thing. Can you change your internal scripts to not 404 when extra GET variables are present? (It is a pretty strange way for them to behave)
精彩评论