0

I'm pretty new with JSON and jQuery, so I'll try my best to explain what I cant do. I have this small piece of JSON data


[
    {
        "id": 1,
        "name": "tratta 1",
        "type": "international",
        "from": "Bangkok",
        "to": "home",
    },
    {
        "id": 2,
        "name": "tratta 2",
        "type": "national",
        "from": "home",
        "to": "Rome",
    }
]



[
    {
        "id":1,
        "name":"Boeing 767-300",
        "lun":54.9 ,
        "wingspan":47.6, 
        "vel": 851,
        "vel max":913,
    },
    {
        "id":2,
        "name":"Boeing 737-800",
        "lun":33.4 ,
        "wingspan":35.8, 
        "vel": 840,
        "vel max":945,
    }
]

saved on my disk. I need to access it with jQuery in order to output a table on HTML, but for now I'm only logging with


$.getJSON("js/test.json", function(data){ console.log(data); });


and Firefox console says

Intepretation error XML: non well-formed

What should I do?

davide m.
  • 452
  • 4
  • 19
  • 2
    Possible duplicate of ["not well-formed" warning when loading client-side JSON in Firefox via jQuery.ajax](https://stackoverflow.com/questions/2618959/not-well-formed-warning-when-loading-client-side-json-in-firefox-via-jquery-aj) – Andreas Oct 22 '18 at 15:41
  • 1
    You will also have to fix your "JSON" as this is not valid. – Andreas Oct 22 '18 at 15:42

1 Answers1

1

I think you should use $.ajax instead of getJSON so you can define the dataType properly. Something like this;

   $.ajax({
    type: "GET",
    url: "js/test.json",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: "{}", //if you need to send data to server
    success: function(json) {
       console.log(json)
    },

});
Mücahid Erenler
  • 132
  • 1
  • 10