How to load data from Webservice to DataTables ?

How to load data from Webservice to DataTables ?

headshot9xheadshot9x Posts: 59Questions: 16Answers: 1
edited March 2015 in Free community support

Hello everybody. I have just use DataTable. I write a project demo load data from Webservice to DataTable. My webservice return JSON string. I run my Webservice and return result JSON string

<string xmlns="http://tempuri.org/">
{"Result":[{"LOCATION_ID":"L0001","AREA_ID":null,"LOCATION_NAME":"Ninh Bình","LOCATION_DES":"NB","EDIT_DATE":null,"EDIT_BY":null,"FLAG":false},
{"LOCATION_ID":"L0002","AREA_ID":null,"LOCATION_NAME":"Đồng Nai","LOCATION_DES":"ĐN","EDIT_DATE":null,"EDIT_BY":null,"FLAG":false},
{"LOCATION_ID":"L0003","AREA_ID":null,"LOCATION_NAME":"Quảng Ngãi","LOCATION_DES":"QN","EDIT_DATE":null,"EDIT_BY":null,"FLAG":false}]}
</string>

Ok , I build Test.aspx with follow

<head>
<script type="text/javascript" charset="utf-8">
        $(document).ready(function () {
            $('#example').DataTable({
                "ajax": {
                    "url": "../BUS/WebService.asmx/LIST_LOCATION",
                    "dataSrc": "Result"
                }
                //"columns": [
                //   // { "Result": "LOCATION_ID" },
                //    //{ "Result": "AREA_ID" },
                //    { "Result": "LOCATION_NAME" },
                //    { "Result": "LOCATION_DES" }
                //    //{ "Result": "EDIT_DATE" },
                //    //{ "Result": "EDIT_BY" },
                //    //{ "Result": "FLAG" }
                //]
            });
        });
    </script>
</head>
<body>
    <div class="table-responsive">
        <table id="example" class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>Col 1</th>
                    <th>Col 2</th>
                </tr>
            </thead>
</table>
</div>
</body>

And function get Data from Entity Framework

public static List<LOCATION> ListLocation()
        {
           List<LOCATION> list = db.LOCATIONs.Where(e => e.FLAG == true).ToList();
               return list ;        
        }

In my Webservice.asmx

 [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string  LIST_LOCATION()
        {
            string json = "";
            var list = LocationBus.ViewLocation();
            return json = JsonConvert.SerializeObject(list);
        }

But it error.I am use F12 in Chorme view error code , i see 500 (Internal Server Error)
Can you see it . Thank you

This discussion has been closed.