No data is display when using Ajax with .Net Webservice
No data is display when using Ajax with .Net Webservice
ofern01
Posts: 1Questions: 0Answers: 0
I need to know how to get the data returned from webservice to Datatables. The first sample here works great, but I want to use the second approach:
sample 1:
[code]
var quoteData
$.ajax({
type: "POST",
url: urlPath,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (resultData) {
if (resultData.hasOwnProperty("d")) { resultData = resultData.d; }
quoteData = $.parseJSON(resultData);
loadGridTable();
},
error: function() {
quoteData = null;
alert("No Data Found");
}
});
function loadGridTable() {
$('#example').DataTable({
"data": quoteData.data,
"columns": [
{ "data": "RepName" },
{ "data": "AgentID" },
{ "data": "AgentName" },
{ "data": "AgentCounty" },
{ "data": "TierID" },
{ "data": "AgentPhone" },
{ "data": "AgentName" },
{ "data": "AgentEmail" },
{ "data": "LOB" },
{ "data": "DocumentNum" }
]
});
}
[/code]
sample 2:
[code]
$('#example').DataTable({
"ajax":{
type: "POST",
url: urlPath,
contentType: "application/json; charset=utf-8",
dataType: "json",
dataSrc: function (resultData) {
if (resultData.hasOwnProperty("d")) { resultData = resultData.d; }
alert(resultData);
var quoteData = $.parseJSON(resultData);
return quoteData;
}
},
"columns": [
{ "data": "RepName" },
{ "data": "AgentID" },
{ "data": "AgentName" },
{ "data": "AgentCounty" },
{ "data": "TierID" },
{ "data": "AgentPhone" },
{ "data": "AgentName" },
{ "data": "AgentEmail" },
{ "data": "LOB" },
{ "data": "DocumentNum" }
]
});
[/code]
This discussion has been closed.