One issue, especially when creating AJAX applications, is that the browser can cache the contents of the page so that when a similar request is made the same content is presented.
To force the browser to present the content you want it to without caching you can add the following headers to your page.
header("HTTP/1.1 202 Accepted"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, proxy-revalidate, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Cache-Control: max-age=10000000, s-maxage=1000000"); header("Pragma: no-cache");
Remember to put this before you print out any content as you will get some nice looking errors otherwise.
Also, I wouldn't put this on every page on the site as it can create an overhead that just isn't needed.
Some browsers, like IE, will still not work as expected here. If the browser is still not giving the content you want then try to add a random number to your GET or POST request. This makes the browser think that the content will be different.