JQuery get ajax call not working in IE

Posted in JQuery on May 5th, 2010 by taswar

So for some reason IE just loves to cache things for you when you call an ajax method.

Something like

?View Code JAVASCRIPT
1
2
3
4
5
 
  $('#mybutton').live('click', function() {
      $.post('SaveLanguage', { lang : $(this).val(), null, null);
      $.get('GetLanguage', null, function(html) { $('#myDiv').replaceWith(html); });
  });

This will work every time in firefox but IE will just call the cache version, thus whatever you have changed in the post version would not matter.

To fix this one can use datetime to append to the query string in each call or just use jquery ajaxSetup like

?View Code JAVASCRIPT
1
2
3
4
5
6
7
 
$.ajaxSetup({ cache: false});
 
  $('#mybutton').live('click', function() {
      $.post('SaveLanguage', { lang : $(this).val(), null, null);
      $.get('GetLanguage', null, function(html) { $('#myDiv').replaceWith(html); });
  });

or use the $.ajax call and pass in cache: false.

Share

2 Responses

  1. jas Says:

    great! I just changed get to post and now it’s working everytime in IE

  2. Ayan Dutta Says:

    Wonderful ! I was having the same problem . It helped me a lot to fix .Many thanks .

Leave a Comment