Skip to content

Instantly share code, notes, and snippets.

@ikawka
Created January 28, 2014 16:20
Show Gist options
  • Select an option

  • Save ikawka/8670868 to your computer and use it in GitHub Desktop.

Select an option

Save ikawka/8670868 to your computer and use it in GitHub Desktop.
Prevent IE from caching your ajax urls
function randomString(len){
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = len;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
//this is will hijack all the ajax request made through jquery
//and dynamically add our random string using the function above
$(function(){
$(document).ajaxSend(function(e, jqxhr, settings) {
settings.url += (settings.url.match(/\?reqid/) ? "" : ("/?reqid="+ randomString(8)));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment