Home > Developer, Fixes & Tips, Web / Internets > QuickFix: jQuery $.getJSON() fails in IE6 & IE7

QuickFix: jQuery $.getJSON() fails in IE6 & IE7

October 27th, 2009 Leave a comment Go to comments

Had a nasty issue with jQuery + jSON + IEx just now – still at work because of it!

This bit of code works perfectly fine on Firefox and Chrome:

function onUnitsModified() {
            $.getJSON("<%=Url.Action("GetTotalUnitCount", "ProjectReaper")%>", null, function(result) {
                if(result > 0)
                  // Do stuffs here
                }
            });
            return true;
}

But in IE we’ve come to realise that the first hit is successful, future json requests ones are not hitting the ASP.NET MVC actions (I put a breakpoint). You could append a time stamp to get rid of this annoying caching bug, but alternatively you can use the ajaxSetup options to disable caching.

function onUnitsModified() {
            $.ajaxSetup ({ cache: false}); 
            $.getJSON("<%=Url.Action("GetTotalUnitCount", "ProjectReaper")%>", null, function(result) {
                if(result > 0)
                  // Do stuffs here
                }
            });
            return true;
}

Darnit! Hope someone else doesn’t waste their time trying to fix this now 🙂

{lang: 'en-GB'}
Share
  1. November 27th, 2009 at 11:23 | #1

    Thanks, this has been driving me nuts all week! You saved me a few more days of head scratching 🙂

  2. Hieu Nguyen Trong
    December 7th, 2009 at 21:19 | #2

    Thanks a lot. This is the quickest fix ever.

  3. January 8th, 2010 at 17:19 | #3

    Thanks a lot,!

  4. Gert
    March 4th, 2010 at 21:52 | #4

    Grrrrr… just spent two hours on this! Thanks!!!

  5. feroz
    April 19th, 2010 at 17:27 | #5

    One of the gr8 and fastest fix ever………thanks!!!!!!!!!

  6. liu bin
    April 26th, 2010 at 18:28 | #6

    Thank you for saving time…

  7. TheSaint
    June 24th, 2010 at 19:55 | #7

    Awesome……. I’ve been trying ot fix this issue for the last 2 days now….
    Thanks soo much…

  8. Alcatraz
    March 10th, 2011 at 01:20 | #8

    Thank you !!!!!

  9. Giji
    June 3rd, 2011 at 20:47 | #9

    Thank you very much. I tried several ways but din’t work. Thanks for the post.

  10. July 29th, 2011 at 17:39 | #10

    Thnx help alot , clearing cache from server side didnot solve the problem , but $.ajax done the game . cheers Thanx alot for posting this

  11. Sreekanth Madineni
    September 7th, 2011 at 22:36 | #11

    Hi,

    Thanks a lot….

  12. Lalit Bansal
    October 17th, 2011 at 19:58 | #12

    Hi..

    I used this line in my javascript function

    $.ajaxSettings.cache=false;

    in place of

    $.ajaxSetup ({ cache: false});.

    So i want to know, which one is best to sort out this problem.
    Please reply…

  13. Geoff
    March 21st, 2012 at 09:25 | #13

    I love you for this!!!

  14. March 27th, 2012 at 09:14 | #14

    $.ajaxSetup({ cache: false }); is the way. You saved me days.

  15. Eduardo Escamilla
    June 27th, 2012 at 02:35 | #15

    $.ajaxSetup ({ cache: false}); genial, genial…. Gracias a Dios existen personas como ustedes !!!… Me han ahorrado mucho, mucho tiempo… gracias!!!!

  1. September 14th, 2010 at 03:14 | #1
  2. September 14th, 2010 at 03:14 | #2