开发者

Json jquery Ie8 issue

开发者 https://www.devze.com 2023-02-03 18:12 出处:网络
I try to understand where is my mistake, and I cannot find it: this is my code javascript: $(document).ready(function(){

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

javascript:

  $(document).ready(function(){
        开发者_如何学Python$.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!


You have invalid JSON, a trailing comma:

    },

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消