Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82015

How to make Ajax call to asp.net web services to pull data into DataTables?

$
0
0
Hi, I'm new to jQuery and DataTable, I'm wondering how to use DataTables in ASP.NET applications, especially how to make Ajax call to web service. You know the asp.net web service will return json like this:
{"d":[{"__type":"DataAccessLayer.CustomerInfo","CustomerID":1,"Name":"Google","Subsidiary":"G","ConfigName":"Gconfig"}], ....}
DataTables will recognize this format as invalid.

Following is my client side code:
        $(document).ready(function () {
            $("#CustomerTable").dataTable({
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": "WebServices/CustomerService.asmx/GetCustomers",
                "fnServerData": function (sSource, aoData, fnCallBack) {
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: sSource,
                        //data: aoData,
                        contentType: "application/json; charset=utf-8",
                        success: fnCallBack
                    });
                }

            });
        });

And my web service method:
        [WebMethod]
        public List<CustomerInfo> GetCustomers()
        {
            CustomInfoBll ci = new CustomInfoBll();
            return ci.GetCustomers();
        }

Could anybody guide me how to use DataTables AJAX in ASP.NET? Any help is appreciated! Thanks in advance!

Best Regards,
Sven [A guy from China]

Viewing all articles
Browse latest Browse all 82015

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>