0

I try to understand where is my mistake, and I cannot find it: this is my code

javascript:

  $(document).ready(function(){
        $.getJSON('ajax/data.json', function(data) {
             $.each(data.results, function(i,item){
                    alert(item.foo);
                });
        });
    });

and data.json file:

{
    "results":[
        {
          "foo": "The quick brown fox jumps over the lazy dog.",
          "bar": "ABCDEFG",
          "baz": [52, 97]
        },
        {
          "foo": "The quick brown fox jumps over the lazy dog.",
          "bar": "ABCDEFG",
          "baz": [52, 97]
        },
    ]
}

Works fine in IE7, FF, but doesn't work in IE8

Can you help me, what's wrong here?

PS: using 1.4.3 jquery version

Thanks!

0

2 Answers 2

3

You have invalid JSON, a trailing comma:

    },

This is illegal JSON, tolerated by all browsers except IE.

Sign up to request clarification or add additional context in comments.

Comments

1

Your problem is that you are using the alert javascript function for debugging, which is a blocking call. It changes the behavior of the javascript. For debugging purposes use jQuery to add the item to a ul or debug using firebug.

$(document).ready(function(){
    $.getJSON('ajax/data.json', function(data) {
         $.each(data.results, function(i,item){
                $('<li>').text(item.foo).appendTo('#results');
            });
    });
});

<body>
<ul id="results">
</ul>
</body>

Using this approach worked for me in FF and IE8.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.