jQuery getJSON syntax error on a valid JSON jQuery getJSON syntax error on a valid JSON ajax ajax

jQuery getJSON syntax error on a valid JSON


The reason this happens is because you're using a local file, so a mime type of "text/xml" is implied and hence Firefox will try to parse it as XML into .responseXML of the underlying XHR object. This of course fails.

You may just ignore this, or specify the mimeType yourself:

$.ajax({    dataType: "json",    url: "json.json",    mimeType: "application/json",    success: function(result){        $.each(result, function(i, obj) {            $("form").append($('<label for="'+i+'">'+obj.title+'</label>'));            $("form").append($('<input id="'+i+'" value="'+obj.value+'" type="text"/><br>'));        });    }});

PS: Using plain XHR you would use overrideMimeType()


I ran the same code on a webserver and no syntax error is generated. While it generates a syntax error when loaded from file:///. SO, it's basically the "scheme".


I think, error produced because of json file is a local file. Try to load with your webserver, like nginx or apache.