Datatables invalid json that's actually valid?

Datatables invalid json that's actually valid?

JbocookJbocook Posts: 6Questions: 3Answers: 0

My json is passing validation. But when data tables pulls it from ajax I get the invalid json error. What am I missing?

My json:

[{"category":"","user_display":"","appchk_txt":"Driver's License ","appchk_rid":"121","user_txt":"","appchk_cod":"DL"},{"category":"","user_display":"","appchk_txt":"Reference ","appchk_rid":"128","user_txt":"","appchk_cod":"RF"},{"category":"","user_display":"","appchk_txt":"Reference: School Counselor ","appchk_rid":"149","user_txt":"","appchk_cod":"11"}]

Answers

  • allanallan Posts: 63,685Questions: 1Answers: 10,500 Site admin

    There must be some other data being returned that is making the data invalid JSON. Can you link to the page or use the DataTables debugger, as per the forum rules please.

    Allan

  • kendulinkendulin Posts: 5Questions: 0Answers: 0

    From ajax reference:

    " By default DataTables will look for the property data (or aaData for compatibility with DataTables 1.9-) when obtaining data from an Ajax source or for server-side processing"

    So, for example:

    { "aaData": [{"category":"","user_display":"","appchk_txt":"Driver's License ","appchk_rid":"121","user_txt":"","appchk_cod":"DL"},{"category":"","user_display":"","appchk_txt":"Reference ","appchk_rid":"128","user_txt":"","appchk_cod":"RF"},{"category":"","user_display":"","appchk_txt":"Reference: School Counselor ","appchk_rid":"149","user_txt":"","appchk_cod":"11"}]}
    
  • allanallan Posts: 63,685Questions: 1Answers: 10,500 Site admin

    I'm not entirely certain what baring that has on the Invalid JSON error? Both of what you posted are valid JSON, but if you are getting an error from DataTables stating that the JSON is invalid, then a JSON parsing error is being reported by jQuery. As I say, we would need either a link to the page or a debugger trace to offer any help resolving the problem.

    Allan

  • kendulinkendulin Posts: 5Questions: 0Answers: 0

    I was fooling around with the issue and was getting Invalid JSON response when not including the data in the aaData property. When testing again to send to you it does not. I must have actually been testing with bad JSON. Sorry to waste time.

This discussion has been closed.