tags:

views:

86

answers:

3

I'm using this code as the starting point to an overhaul of our JavaScript framework:

$("#get").click(function(){
    $("#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!

+2  A: 

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/

Marko Dumic
he can try this too, but i guess that cache should be true :P
markcial
You're right, thanks! Fixed that.
Marko Dumic
Ah I see, that makes sense. Google was just an example, we can probably convert our internal scripts to prevent 404s :-), many thanks for your answer!
ILMV
You still have cache:false in your explanation. :p
mkj
@mkj: sorry. ;)
Marko Dumic
+1  A: 

Try this, before any $.get put this code

$.ajaxSetup({cache:true});
markcial
+1  A: 

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)

ZoFreX
Yes I can, this question was more about understanding the problem so I can make the correct decisions. Thanks :)
ILMV