Reputation: 35
I tried to create table using datatable.js ajax. I'm getting data from webmethod , but, result is not adding into the tables.
JS Method
function getMyData() {
alert('d');
$.ajax({
type: "POST",
url: "AssignHistory.aspx/getModemAssign ",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: buildMyDatatable,
error:
function (msg) {
alert(msg.status + " " + msg.statusText);
}
});
function buildMyDatatable(result) {
var data = JSON.stringify(result.d);
$('#gvAssgin').dataTable({
retrieve: true,
JSON:data,
columns: [
{ data: "ModemId" },
{ data: "ModemName" }
]
});
}
}
HTML Code
<table id="gvAssgin">
<thead>
<tr>
<th>
Modem ID
</th>
<th>
Modem Name
</th>
</tr>
</thead>
waiting for replies
Upvotes: 1
Views: 58
Reputation: 58880
Correct option of JavaScript sourced data is data
. Also there is no need to generate JSON again with JSON.stringify(result.d)
, just pass the array to jQuery DataTables.
See the corrected code below:
$('#gvAssgin').dataTable({
data: result.d,
columns: [
{ data: "ModemId" },
{ data: "ModemName" }
]
});
Upvotes: 1