Loading a table from an Ajax call
Loading a table from an Ajax call
The docs all show Ajax calls loading data from a file. I'm making a real AJAX call and what happens is that an empty table gets rendered before the server has returned the data. My code is below.
The good news is that the Ajax call is being made. I can see the response on the server side. The server returns valid JSON (checked with JSON lint).
I'd appreciate any feedback on my code and pointers to examples of using Datatables with real AJAX calls (not reading JSON from files).
Thanks.
[code]
Serial Number
Sales Order
Part Number
Part Description
Shipped Date
Date Sold
Status
$(function() {
$("#example").dataTable({
"bServerSide": true,
"sAjaxSource": "http://localhost:8080/mtprest/Product/productByStatus?status=awaiting",
"aoColumns": [{
"mData":"serialNumber"
},{
"mData": "sONumber"
},{
"mData": "partNumber"
},{
"mData": "desc"
},{
"mData":"shippedDate"
},{
"mData":"soldDate"
},{
"mData":"status"
}
]
});
});
[/code]
The good news is that the Ajax call is being made. I can see the response on the server side. The server returns valid JSON (checked with JSON lint).
I'd appreciate any feedback on my code and pointers to examples of using Datatables with real AJAX calls (not reading JSON from files).
Thanks.
[code]
Serial Number
Sales Order
Part Number
Part Description
Shipped Date
Date Sold
Status
$(function() {
$("#example").dataTable({
"bServerSide": true,
"sAjaxSource": "http://localhost:8080/mtprest/Product/productByStatus?status=awaiting",
"aoColumns": [{
"mData":"serialNumber"
},{
"mData": "sONumber"
},{
"mData": "partNumber"
},{
"mData": "desc"
},{
"mData":"shippedDate"
},{
"mData":"soldDate"
},{
"mData":"status"
}
]
});
});
[/code]
This discussion has been closed.
Replies
[code]
{"iTotalRecords":12,"iTotalDisplayRecords":0,"sEcho":"","aaData":[{"productId":47209009,"serialNumber":"0909090","sONumber":"dev35001484_","partNumber":"987654KP-GL","desc":"TEST MEC","shippedDate":null,"soldDate":null,"status":"Awaiting Validation"}, ...}
[/code]
[code]
"sAjaxSource": "product.awaiting.json",
[/code]
and it worked. So it is a problem with Datatables not waiting for the web service call to return with the data.
sEcho should be 1 or higher - http://datatables.net/usage/server-side . Might possibly be that...
Allan
[quote]An unaltered copy of sEcho sent from the client side. [/quote]
My AJAX call is a GET to a restful web service and I include one parameter. Do I also have to send sEcho, and if so where do I get the current value of sEcho?
Is sEcho an int that I increment with each call starting at 1?