GET method and Internet Explorer workaround
This post is just a note for those who have not experienced WCF, REST, GET method and Internet Explorer in combination or AJAX, GET method and Internet Explorer again. Actually the problem is that the browser is greedy for caching and If you use a GET method to send an asynchronous request to your server side code, Internet Explorer by default will cache locally your request, so obviously you won't have the latest result in your response.
This is not particularly pleasant situation if you don't know that this behavior applies to all GET methods! Note it that this behavior is especially for Internet Explorer and it’s not a case for other popular browsers such as Firefox, Chrome and Safari. For solving this issue, there is one simple workaround explained in this article.
Unique parameter for each request
Add additional unique parameter to your URL for each request. The most simplest and effective snippet useful for me is to add a timestamp to the end of your request:
function UniqueUrl(url) {
var timeStamp = +new Date;
// add timestamp to the end
url = url + (url.match(/\?/) ? '&' : '?') + '_=' + timeStamp;
return url;
}
and then simply you can call it as:
UniqueUrl('http://mkdot.net/MyService.svc/GetData/1');
UniqueUrl('http://mkdot.net/MyService.svc/GetData/1?param=true');
to generate unique URL such as: http://mkdot.net/MyService.svc/GetData/1?_=1247691453959 or http://mkdot.net/MyService.svc/GetData/1?param=true&_=1247691453959 appropriately. This will force IE to show a fresh version of your request all the time.
Happy coding!