Created
January 28, 2014 16:20
-
-
Save ikawka/8670868 to your computer and use it in GitHub Desktop.
Prevent IE from caching your ajax urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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