Ajax call delivers valid JSON on one page but invalid on another with basically same code

Ajax call delivers valid JSON on one page but invalid on another with basically same code

rminterrminter Posts: 6Questions: 2Answers: 0

I am having an issue with two subdomains using basically the same code for a dataTable that does the same thing for each table with one less column in one than the other. On one subdomain the code works fine and everything is returned as expected. On the other, I am getting and error stating "DataTables warning: table id=sortable - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1". I have checked the JSON using JSONLint and it says the JSON is valid. I have created a debug page located at: https://debug.datatables.net/imibax. I can not find the issue at all. Any help would be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • rminterrminter Posts: 6Questions: 2Answers: 0

    Anyone? Anyone?

  • rminterrminter Posts: 6Questions: 2Answers: 0
  • allanallan Posts: 63,785Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Hi,

    Sorry you haven't received a reply before. The JSON from the debug trace is index valid which suggests that the returned data from the server contains a UTF8 BOM at the start, making the data invalid JSON.

    Unfortunately, the DataTables debugged can't show if that is the case or not (it doesn't get the BOM from the data, if it does exist).

    What I would suggest is that you use cURL or similar to make a request for the raw data and save it into a file. Then use a hex viewer to check the first three bytes for EF BB BF. If that is the case, then the BOM is the issue and it needs to be removed from the return from the server.

    If you have a link to the page you can provide I'd be happy to check it.

    Allan

  • rminterrminter Posts: 6Questions: 2Answers: 0

    Thank you Allan! That is exactly what it was. It had a tab before the data. Remove that and it works fine.

This discussion has been closed.