DataTables warning: table id=suburbs_table - Invalid JSON response.

DataTables warning: table id=suburbs_table - Invalid JSON response.

sjw01sjw01 Posts: 67Questions: 36Answers: 1

I am using PHP and json_encode to encode the data.

The data coming back is JSON:

SAMPLE:

[{"id":"6","postcode":"4001","locality":"BRISBANE","deliverTo":"1","charge_extra":"0"},{"id":"8","postcode":"4004","locality":"SPRING HILL (4004)","deliverTo":"1","charge_extra":"0"},{"id":"9","postcode":"4000","locality":"SPRING HILL (4000)","deliverTo":"1","charge_extra":"0"},{"id":"10","postcode":"4005","locality":"NEW FARM","deliverTo":"1","charge_extra":"0"},{"id":"11","postcode":"4005","locality":"TENERIFFE","deliverTo":"1","charge_extra":"0"},{"id":"12","postcode":"4006","locality":"BOWEN HILLS","deliverTo":"1","charge_extra":"0"},{"id":"13","postcode":"4006","locality":"FORTITUDE VALLEY","deliverTo":"1","charge_extra":"0"},{"id":"15","postcode":"4006","locality":"HERSTON","deliverTo":"1","charge_extra":"0"},{"id":"16","postcode":"4006","locality":"NEWSTEAD","deliverTo":"1","charge_extra":"0"},{"id":"17","postcode":"4007","locality":"ASCOT","deliverTo":"1","charge_extra":"0"},{"id":"18","postcode":"4007","locality":"HAMILTON","deliverTo":"1","charge_extra":"0"},{"id":"20","postcode":"4008","locality":"BRISBANE AIRPORT","deliverTo":"1","charge_extra":"0"},{"id":"21","postcode":"4008","locality":"PINKENBA","deliverTo":"1","charge_extra":"0"},{"id":"22","postcode":"4009","locality":"EAGLE FARM","deliverTo":"1","charge_extra":"0"},{"id":"24","postcode":"4010","locality":"ALBION","deliverTo":"1","charge_extra":"0"},{"id":"27","postcode":"4011","locality":"CLAYFIELD","deliverTo":"1","charge_extra":"0"},{"id":"28","postcode":"4011","locality":"HENDRA","deliverTo":"1","charge_extra":"0"},{"id":"29","postcode":"4012","locality":"NUNDAH","deliverTo":"1","charge_extra":"0"},{"id":"30","postcode":"4012","locality":"TOOMBUL","deliverTo":"1","charge_extra":"0"},{"id":"31","postcode":"4012","locality":"WAVELL HEIGHTS","deliverTo":"1","charge_extra":"0"},{"id":"33","postcode":"4013","locality":"NORTHGATE","deliverTo":"1","charge_extra":"0"},{"id":"34","postcode":"4014","locality":"BANYO","deliverTo":"1","charge_extra":"0"},{"id":"35","postcode":"4014","locality":"NUDGEE","deliverTo":"1","charge_extra":"0"},{"id":"36","postcode":"4014","locality":"NUDGEE BEACH","deliverTo":"1","charge_extra":"0"},{"id":"37","postcode":"4014","locality":"VIRGINIA","deliverTo":"1","charge_extra":"0"},{"id":"40","postcode":"4017","locality":"BRACKEN RIDGE","deliverTo":"1","charge_extra":"0"},{"id":"41","postcode":"4017","locality":"BRIGHTON","deliverTo":"1","charge_extra":"0"},{"id":"44","postcode":"4017","locality":"DEAGON","deliverTo":"1","charge_extra":"0"},{"id":"45","postcode":"4017","locality":"SANDGATE","deliverTo":"1","charge_extra":"0"},{"id":"47","postcode":"4017","locality":"SHORNCLIFFE","deliverTo":"1","charge_extra":"0"}]

I'm pretty sure that is a valid JSON string.
The error says visit: http://datatables.net/tn/1 which only appears to validate that my data is in fact JSON.

I don't know where to go now???

Replies

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Have you set ajax.dataSrc to be ''? If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • sjw01sjw01 Posts: 67Questions: 36Answers: 1

    I added ["data": []] around the JSON.
    Prob something that could be added to the help page: http://datatables.net/tn/1

This discussion has been closed.