Jquery – $.getJSON() is not working with chrome,Why

ajaxjquery

This code works fine in FF and safari,Not in Chrome why?

$.getJSON('s.json', function(data) {
    var items = [];

    $.each(data, function(key, val) {
        items.push('<li id="' + key + '">' + val + '</li>');
    });

    $('<ul/>', {
        'class' : 'my-new-list',
        html : items.join('')
    }).appendTo('body');
});

Best Solution

I had exactly the same problem, and the issue was that my json was not valid (it had hidden tab characters in it). Chrome seems to be more strict than the other browsers.

Check the response with a .error function eg,

$.getJSON('s.json', function(data) {
  //...
})
.error(function(data) {
  console.log("Error!");
});

You could also try validating the output with something like http://jsonlint.com/