How to load data to DataTable ?
How to load data to DataTable ?
![headshot9x](https://secure.gravatar.com/avatar/54589dfd3263a2292883dab6c31c9a76/?default=https%3A%2F%2Fvanillicon.com%2F54589dfd3263a2292883dab6c31c9a76_200.png&rating=g&size=120)
I try load data from JSON string (using Webservice in Entity framework) to DataTable., It is same work , but run it , it get error
...table id=example - Invalid JSON respone ......please see http://datatables.net/tn/1...
In here , my page.aspx
$(document).ready(function () {
$('#example').DataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../BUS/WebService.asmx/ListLocation",
"sServerMethod": "POST",
"sAjaxDataProp": "",
"aoColumns": [
{ "mData": "LOCATION_ID" },
{ "mData": "AREA_ID" },
{ "mData": "LOCATION_NAME" },
{ "mData": "LOCATION_DES" },
{ "mData": "EDIT_DATE" },
{ "mData": "EDIT_BY" },
{ "mData": "FLAG" }
]
});
});
And my JSON data
[
{
"LOCATION_ID": "L0001",
"AREA_ID": "A0001",
"LOCATION_NAME": "Ninh Bình",
"LOCATION_DES": "NB",
"EDIT_DATE": "2014-11-05T00:00:00",
"EDIT_BY": "user 1",
"FLAG": true,
"AREA": null,
"TOPICs": [],
"USERS_PROFILE": []
},
{
"LOCATION_ID": "L0002",
"AREA_ID": "A0002",
"LOCATION_NAME": "Đồng Nai",
"LOCATION_DES": "ĐN",
"EDIT_DATE": "2014-11-05T00:00:00",
"EDIT_BY": "user 1",
"FLAG": true,
"AREA": null,
"TOPICs": [],
"USERS_PROFILE": []
},
{
"LOCATION_ID": "L0006",
"AREA_ID": "A0003",
"LOCATION_NAME": "Huế",
"LOCATION_DES": "H",
"EDIT_DATE": "2014-11-05T00:00:00",
"EDIT_BY": "user 1",
"FLAG": true,
"AREA": null,
"TOPICs": [],
"USERS_PROFILE": []
}
]
Can you tell me which i wrong in here . thank you.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I had the same problem, and for me what was missing was this code:
dataType: "json"
you can put it before the
aoColumns
. Hope it fix your problem.Hi celsomtrindade. I try with your advice , but it is error. I use Google Chorme debug and I see it convert my Json to text/xml ? What going on in here ?
Everybody give me advice. (Somebody as Allan)
Hi allan , I read in https://debug.datatables.net/ , and debug code is "enupex" , please see it . thank you so much.