November 7th, 2010 Comments: 0
When developing my webapp, I ran into a problem where IE (and only IE) would cache my ajax requests I made to a certain PHP file. Basically if IE detects that the browser is making the same AJAX request twice to the same URL it won't it even execute the succeeding one. For certain design structures this could be a problem where you need to be able to poll a server for data. In order to stop IE from doing this I needed to create a function called makeid()
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < 5; i++ )? text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; }
Which basically just generates a random string, and I pass this string into my GET ?AJAX request. However if your using the jQuery library like I am you can set caching to false when you set up your $.ajax function
$.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); } });
jQuery passes in the current time rather than a random string