[AJAX] IE and its stupidity–Part 100255454577 – Ajax Caching


This is a note to anyone who uses Ajax and Http GET requests – turn off cache for each request otherwise IE wont refresh and display the latest response. Good example is in JQuery:

$.ajax({
  type: 'get',
  url: url,
  cache: false,
  success: function(result) {
 $(targetDiv).html(result);
  }

This nice little method allows you to pass a parameter called cache which you need to set to false.

Another method in JScript is to provide dummy URL parameter to fool the old dog into refreshing:

var url = '/accountstest/SiteAdmin/Dashboard' + "?dummy=" + new Date().getTime();

Chrome and Firefox do not have this problem.

Reading AJAX For Dummies

Reading AJAX For Dummies (Photo credit: daveynin)

Enhanced by Zemanta

2 thoughts on “[AJAX] IE and its stupidity–Part 100255454577 – Ajax Caching

  1. You probably meant ?dummy and not &dummy in the example…

    Also, I’ve personally never had a problem with caching, ajax, get and IE if I just set the caching headers.

    Like

    1. Sami Kuhmonen :

      You probably meant ?dummy and not &dummy in the example…

      Also, I’ve personally never had a problem with caching, ajax, get and IE if I just set the caching headers.

      Thanks Sami! This is all new to me, so im learning as im going. How do you set the cache headers? I presume whatever the JQuery im using for the request only turns off the cache on a request-by-request basis?

      Also, ive updated my dummy statement, good spot! 🙂

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s