开发者

How to change request to avoid cached results?

开发者 https://www.devze.com 2023-03-16 01:11 出处:网络
I get xml file from server with function ( JQuery ) function load_config_xml(){ $.ajax({ url: \'config/conf.xml\',

I get xml file from server with function ( JQuery )

function load_config_xml(){
    $.ajax({
        url: 'config/conf.xml',
        dataType: "xml",
        success:parse_xml,
        error: function(){
            alert("Error during loading xml file");
        }
    });
}

but it doesn't return fresh results, l开发者_开发技巧ighttpd caches. How to change request to avoid cached results ?


Simplest workaround is to explicitly use a POST request. A browser will not cache those:

function load_config_xml(){
    $.ajax({
        url: 'config/conf.xml',
        dataType: "xml",
        type: 'POST',     // here we go
        success:parse_xml,
        error: function(){
            alert("Error during loading xml file");
        }
    });
}

jQuery also offers the option cache which you can set to false. That creates the some outcome:

cache: false

Basically jQuery will just modify the query string for each request, which of course you could do on your own aswell:

url: 'config/conf.xml?cachebuster=' + (+new Date())
0

精彩评论

暂无评论...
验证码 换一张
取 消