I can bind statically with DataTables.net like below:
<script type="text/javascript">
$(document).ready(function () {
$('#testDatatable').dataTable({
"aaData": [
["Ibrahim", 55],
["Asif", 20],
["Shariful", 70],
["John", 55],
["Doe", 40],
["Nazmul", 30],
["Jane", 15],
["Ershad", 10],
["Yusuf", 44],
["Bill", 22],
["Steve", 18]
]
,
"aoColumns": [
{ "sTitle": "Name" },
{ "sTitle": "Age" }
]
});
});
</script>
But for prop aaData I want to fetch the data from a web service. Like below:
<script type="text/javascript">
$(document).ready(function () {
$('#testDatatable').dataTable({
"aaData": $.getJSON('http://localhost:9183/Service.svc/GetCustomer')
,
"aoColumns": [
{ "sTitle": "Name" },
{ "sTitle": "Age" }
]
});
});
</script>
My service looks like this:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<Customer> GetCustomer()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { Name = "Ibrahim", Age = 10 });
customers.Add(new Customer { Name = "John Doe", Age = 20});
return customers;
}
This does not work. It shows that no records were found. Someone please tell me what options do I have or where I am going wrong. Any suggestion is highly appreciated.