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?

2

1 Answer 1

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)
    },

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

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.