How to handle no returned JSON via ajax

How to handle no returned JSON via ajax

budfrogsbudfrogs Posts: 1Questions: 1Answers: 0
edited September 2018 in Free community support

I am using servlet to query a database that sometimes will return no information. If I return null I get an invalid JSON response.

Considering there was no data in the database null is valid. How do you handle no returned data or provide a response to DataTables in a JSON format that you can intercept and display a different message in the table?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,994Questions: 1Answers: 10,368 Site admin
    Answer ✓

    null might be valid from the database, but it isn't valid JSON. Try typing "null" into JSONLint.

    For DataTables, when there are no records to display, you should pass it an empty array - e.g.:

    {
      "data": []
    }
    

    (assuming you are using the default data property).

    Allan

This discussion has been closed.