Tuesday, February 1, 2011

Getting JSON and JQuery .getJSON to work in IE8

To no surprise my code that was working 100% in FF died a horrible death in IE8.

Here's what I had to do to get it to work.

1) Set Header to:
response.setContentType("text/javascript; charset=UTF-8");   
Source: http://stackoverflow.com/questions/3517608/why-isnt-this-simple-bit-of-jquery-getjson-working-in-ie8

2) Prevent I8 from caching my Ajax requests:
$.ajaxSetup({ cache: false });
$.getJSON("/MyQueryUrl",
   function(data) {
     // do stuff with callback data
     $.ajaxSetup({ cache: true });
   });
Source: http://stackoverflow.com/questions/264216/getjson-returning-cached-data-in-ie8
 
3) Add JSON support to IE8
Basically just include json2.js in my script. 
Source: http://www.json.org/ 
 
Don't we all just 'love' IE


No comments:

Followers