IE Caching Ajax Results – How to fix

Updated (25/06/2010): Fixed typos in code example
Updated (16/11/2012): Fixed missing comma. 

I have been working on a website recently and one of the pages on the site has a  main functionality of showing dynamic results returned from a AJAX
call to a WCF service.

As I was developing and continuously testing with Firefox I was happy to see that my code was working well; based on the URL the results on the page will differ as expected.
However, When it came to test the page with Internet Explorer the results were dramatically different… No matter what the URL was the same content from my initial request kept appearing on the screen! Quickly enough I realized that it wasn’t something wrong with my code but with IE, after all in Firefox and Chrome it was working just fine.

So naturally, I googled for a solution and found this StackOverflow thread that confirmed to me that this was indeed an issue with IE. Unfortunately, the good answers there were only helpful to those who use jQuery to initiate the AJAX requests but I was using the proxy generated automatically by ASP.NET, so I had to find my own solution as I was unable to find anything useful online.

Below are ways you can use to fix the problem. First, I’ll show how to fix it when using the MS Service Proxy and then how to fix it when using jQuery.

Continue reading “IE Caching Ajax Results – How to fix”