Ajax caching issue with IE workaround

If you’ve been developing websites I’m sure you pretty feel a little nausea from browser refreshing after an operation and prefer to work with AJAX for updating, deleting or loading some data from your DB with out the page reloading.

Most commonly used is http request is GET, your script runs flawlessly with Firefox, Chrome and Safari however on IE7 & and IE8 you don’t see the updates. This is because IE 7 and IE 8 treat GET request differently than POST, if there is no change from the last call it will always load up from it’s cache.

The workaround to the issue is pass an ever changing variable to the GET request like the current timestamp or date.

1. You can pass it on the ajax function call by adding an extra parameter time on the ajax call on the page.

ajaxify(x,<?php echo time(); ?>); // ajaxify(keywords, rand_time)

Then on your ajax function xmlHttp request call the rand_time parameter

xmlHttp.open(“GET”,”includes/ajax_page.php?dontcacheme=” + rand_time +”&keywords=”+keywords,true);

2. Or just create the random string using a Javascript Date class.

xmlHttp.open(“GET”,”includes/ajax_page.php?dontcacheme=” + new Date().getTime() +”&keywords=”+keywords,true);

This workaround worked well with my ajax scripts. Hope it helps.

Getting Managed

It’s been awhile since I updated this blog and specially my  personal finance blog. These past 3 days I’ve been integrating a new daily work flow to balance my personal time in blogging, reviewing, learning new skills and time for work.  I’ve been talking about preparing for taking the PHP Zend Certified exam for several months now but I always get tied up with work load.  Working at home has a lot of pros and  alot of cons.  I won’t be diving into the the pros and cons topic here of working at home, just pointing one example is when working at home it can eat up your personal time unlike in the office 9-5 scene once you leave the office your “kinda free”.

On top of my list daily work flow is to start blogging again to get back into the scene, mastering CodeIgniter, review and learn some new skills like photography with my recent acquisition of a DSLR .  And so far based on the recent 3 days I’ve been managing my work flow it is working like a charm.  So expect this blog to be revived with new entries and tutorials this coming days. (I know I said that before but this time it’s for real. LOL).