Invalid JSON response

Invalid JSON response

razvanrazvan Posts: 11Questions: 3Answers: 0

Hi,

I get this message for the following JSON. I first fetch the JSON in a variable (e.g. list) then use that as "data": list.

{"people":[{"Id":"2","firstname":"John","lastname":"Doe"},{"Id":"3","firstname":"Milan","lastname":"Jovovic"},{"Id":"4","firstname":"John","lastname":"Neumann"}]}

Can you tell why is this not valid?

Best Regards,
Razvan

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    That is valid - so there must be something else in the response which is making it not valid.

    Allan

  • razvanrazvan Posts: 11Questions: 3Answers: 0

    Thanks for the reply Allan. When I use "url" parameter for ajax it works:

    "ajax": {
    "url": jsonPeopleURL,
    //"data": peopleData,
    "dataSrc": "people"
    },

    But when I try to get the Json first and save it in a local variable like this

                $.getJSON(jsonPeopleURL, {
                        format : "json"
                    }).done(function(data) {
                        peopleData = data;
    

    });

    and then use
    "ajax": {
    //"url": jsonPeopleURL,
    "data": peopleData,
    "dataSrc": "people"
    },

    It doesn't.

    So I need to save the DataTables Json in a variable so I can use it later. Do you have any suggestions how I can do this? The approach from above should've normally worked, it's the same datasource.

    Thanks!

    Best Regards,
    Razvan

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    It's wouldn't You don't need to use ajax for that since you aren't Ajax fetching the data (as far as DataTables can see). Use the data option if you just want to pass data in that you already have.

    Allan

  • razvanrazvan Posts: 11Questions: 3Answers: 0

    Thanks Allan. You're right, ajax was left there for some reason and it's not needed since this uses the client data.

This discussion has been closed.