Skip to content Skip to sidebar Skip to footer

Json Structure Not Working In Ie7 (javascript)

OK, I'm new to JSON so please forgive me if my question is a little ignorant - I've beat my head against the wall too much and need some expert advice. I'm trying to get a simple e

Solution 1:

OK, figured it out. Wasn't a JSON/JavaScript issue at all but a caching issue. When I was developing this I must have initially tested IE7 when test-ajax.php wasn't working or was producing a different JSON structure and then I changed test-ajax.php to what I posted above and I updated my JavaScript BUT IE7 was using a cached version of what it originally received from test-ajax.php. And I tested this - if I clear the cache in IE7 it works and then if I change the values in the JSON structure (but not the structure itself) IE7 continues to use the cached JSON structure.

Answer :

I added

header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0"); 

in my test-ajax.php page and now IE7 is checking the server properly for a newer version of test-ajax.php when it makes an AJAX call.

Thanks everyone!

Solution 2:

Try adding the following line to the end of the test-ajax.php file:

echo';';

Solution 3:

I don't immediately see anything wrong, but here's some things to try

  1. Get Charles. Look at the request/response from the getJSON() call. Is the content being returned as expected? Is the status code of the response 200, or is it something else?
  2. Determine if IE knows about the json variable at all. Modify your code to try stuff like this

(Probably want to run these alerts only 1 at a time)

$.getJSON("test-ajax.php", function(json){
  alert( typeof json );
  alert( typeof json.var1 );
  alert( typeof json.var1[1] );
});

Solution 4:

The two common problems with IE and ajax are the following :

  • caching ( solution can be found above)
  • white space !! ( if your return has any white space before/after the json output, this will fail in IE 7 )

Solution 5:

I had the same problem with IE 8. The solutions was to simply turn off caching with ajaxSetup

$.ajaxSetup({
cache : false});

Very annoying because this works fine in FF and Chrome.

Post a Comment for "Json Structure Not Working In Ie7 (javascript)"