How to populate my data table with JSON data from Webservice?
How to populate my data table with JSON data from Webservice?
Hi
I have a created a rest webservice, which returns below JSON based on the search
[{"street":"","city":"HOUSTON ","countyCode":"201","countyName":"HARRIS ","stateCode":"TX","stateName":"","zip":"77070","countryName":"","taxAuthShipto":"TX7707000","shipToCityLimit":"0","geoCode":"00","cityIndicator":"0"},
{"street":"","city":"HOUSTON ","countyCode":"201","countyName":"HARRIS ","stateCode":"TX","stateName":"","zip":"77070","countryName":"","taxAuthShipto":"TX7707001","shipToCityLimit":"1","geoCode":"01","cityIndicator":"1"},
{"street":"","city":"WILLOW PLACE ","countyCode":"201","countyName":"HARRIS ","stateCode":"TX","stateName":"","zip":"77070","countryName":"","taxAuthShipto":"TX7707003","shipToCityLimit":"0","geoCode":"03","cityIndicator":"0"}]
I have a search form. Once i click the search button, my search parameters are formed as JSON and passed to webservice through the ajax call and i want to show the results from webservice ( sample is pasted above) in data table. Please help me how to write $('#test').dataTable({ //what to write here })
Thanks
Anuradha K J
Answers
Links below are from the current documentation, you should be able to come up with working code if you've coded your own webservice.
See: "Get JSON data from a file via Ajax.:"
https://datatables.net/reference/option/ajax
https://datatables.net/reference/api/ajax.json()
See the link in the FAQ JSON Question for technical debugging
http://datatables.net/faqs/#json
Thanks Anag.. But i tried below things.. its not even hitting my webservice
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
$(document).ready(function() {
var table = $('#example').DataTable();
} );
</script>
</head>
<body class="dt-example">
</body>
</html>
// My Input to webservice : turn the jsonData object into a string so it can be passed to the webservice
var jsonData = JSON.stringify(jsonDataObject);
jQuery.support.cors = true;
$('#example').dataTable( {
"ajax": {
"type": "POST",
"data" :jsonData,
"url":"http://localhost:7001/WSVzipTaxwareClient/testService/testPostJSON",
}
} );
Giving canot reinitialise data table alert