Requested Unknown Parameter - http://datatables.net/tn/4

Requested Unknown Parameter - http://datatables.net/tn/4

jbaronjbaron Posts: 2Questions: 1Answers: 0

Hello - very new to datatables and I can't seem to figure out this issue.

Javascript:

$(document).ready(function () { $.ajax({ url: 'http://localhost:61009/api/TableData', method: 'post', dataType: 'json', success: function (data) { $('#example').DataTable({ data: data, columns: [ { data: 'FirstName' } ] }); } }); });

HTML Code:

<body>
<table id="example">
<thead>
<tr>
<th>FirstName</th>
</tr>
</thead>
<tfoot>
<tr>
<th>FirstName</th>
</tr>
</tfoot>
</table>
</body>

My Web Service Returns the following JSON:

"{\"data\":[{\"FirstName\":\"John\"},{\"FirstName\":\"Fred\"}]}"

Which parses as valid JSON. The funny thing is if I save the JSON string as a file and (removing the escape characters) specify that as my JSON via the AJAX property it works. Any help would be greatly appreciated.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,887Questions: 1Answers: 10,140 Site admin
    Answer ✓

    Your web-service is returning a string, not a JSON object. You need to return:

    { "data": [ ... ] }
    

    Note the lack of outer quotes.

    Allan

  • jbaronjbaron Posts: 2Questions: 1Answers: 0

    That was it! Thank you so much!

This discussion has been closed.