How to change request to avoid cached results?
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())
精彩评论