Is your jQuery get() method not loading new content? Here’s the fix!

I came across this problem today when I had a javascript function that used a setInterval() method and jQuery’s get() method to refresh a simple news alert ticker. The issue I had was that while the function was triggering fine, and I had modified and saved a new version of the file I was trying to pull in, Internet Explorer wasn’t playing nice and kept re-loading its cached version.

After a quick search through Google I managed to find this neat if slightly hacky solution on JQuery HowTo:

// Reload mypage.html every 5 seconds
var refresh = setInterval(function()
{
    $('#mydiv').load("mypage.htm?" + 1*new Date() );
}, 5000);

This simple solution tricks the browser in to thinking it is pulling a unique file each time by adding a query string to the end of the uri. The query string won’t have any adverse affect on my code or the data being pulled in – all in all a very neat solution to an awkward problem!

You can read the full article over here -> http://jquery-howto.blogspot.com/2009/04/jquery-ajax-functions-load-get-etc-are.html