Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 1816

Binding DataTables with a WCF Service

$
0
0
According to the thread here: http://datatables.net/forums/discussion/7949/getting-cannot-read-property-length-of-undefined-in-chrome-error/p1
I have the following in place in my client:
$('#testDatatable').dataTable({
                    "bProcessing": true,
                     //Works fine if Data.txt is used instead of service here
                    "sAjaxSource": 'http://localhost:9183/Service.svc/GetCustomer',
                    "aoColumns": [
                        { "mData": "Age" },
                        { "mData": "Name" }
                    ]
                });
This is what my service is returning just like datatables accept:
        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        public string GetCustomer()
        {
            List<Customer> customers = new List<Customer>();
            customers.Add(new Customer { Name = "Ibrahim", Age = 10 });
            customers.Add(new Customer { Name = "John Doe", Age = 20});

            JavaScriptSerializer js = new JavaScriptSerializer();
            string returnArray = @"{ ""aaData"":"+js.Serialize(customers)+"}";
            return returnArray;
        }

But upon running I get the following error:
Uncaught TypeError: Cannot read property 'length' of undefined

If I am using data filled .txt file with the same string that is being returned from my service instead of my service then it is working fine.
Why?? What is the difference here?
I have been stuck here for 2 days now. Someone please show the way.

Viewing all articles
Browse latest Browse all 1816

Trending Articles