How to load data to DataTable ?

How to load data to DataTable ?

headshot9xheadshot9x Posts: 59Questions: 16Answers: 1

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

Answers

  • celsomtrindadecelsomtrindade Posts: 4Questions: 2Answers: 1
    Answer ✓

    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.

  • headshot9xheadshot9x Posts: 59Questions: 16Answers: 1

    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 ?

    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://tempuri.org/">[{"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":[]}]</string>
    

    Everybody give me advice. (Somebody as Allan)

  • headshot9xheadshot9x Posts: 59Questions: 16Answers: 1

    Hi allan , I read in https://debug.datatables.net/ , and debug code is "enupex" , please see it . thank you so much.

This discussion has been closed.