views:

152

answers:

2

jQuery 1.4.2 omits the timestamp GET parameter (to defeat browser cacheing) if I assert the ajax cache setting in the local context:

$.ajax({
    url: searcher, 
    data: keys,
    cache: true,
    type: 'GET',
    dataType: 'json',
    success: function(data) {
        // something
    });

But it includes timestamp if I move the setting out of there and into the global context:

$.ajaxSetup({cache: true});

Moreover, if I let the default apply, jQuery sets timestamp, which doesn't seem to match the manual.

Do you experience the same?

Do HTTP cache control response headers from the server affect this jQuery feature?

A: 

You can manually add a timestamp as a get parameter, that would be a totally fine workaround right?

function myAjaxFunction()
{
    var tS=new Date().getTime();
    $.ajax({
        url: searcher,
        data: {timestamp:tS},
        cache: true,
        type: 'GET',
        dataType: 'json',
        success: function(data) {
            //something here
        }});
}
Trafalmadorian
A: 

Looks like it works. The following three ajax calls only passes a timestamp as a parameter in the 2nd case. The name of the timestamp parameter is not timestamp, but rather a blank character.

    $.ajax({ url: '/?=testDefault',
    data: { 'cache': 'default' }
    });//no timestamp

    $.ajaxSetup({ cache: false });
    $.ajax({ url: '/?=testFalse/',
    data: { 'cache': 'false' }
    });//yes, a timestamp

    $.ajaxSetup({ cache: true });
    $.ajax({ url: '/?=testTrue/',
    data: { 'cache': 'true' }
    }); //no timestamp

As an aside, are you using an autocomplete plugin? That passes a timestamp parameter by default. You can override it using the extraParams option by passing something like this.

extaParams: {timestamp:'cache'}
James Lawruk
It is an underscore, not a blank character.
Chetan Sastry