DataTables expects the returned value to be an object with a property called
data
which contains the list of data to display:
ajax | Options | DataTables.net[
^]
An ASP.NET WebMethod always wraps the returned object in an object with a property called
d
, to try to avoid a potential CSRF issue if the result is an array:
Anatomy of a Subtle JSON Vulnerability | You’ve Been Haacked[
^]
You've also double-encoded the result - your web method should just return the data directly, rather than JSON-encoding it.
Once you've changed your web method to remove the extra JSON encoding, you can use the
dataFilter
option in your script to modify the returned data to match the expected format. For example:
"ajax": {
...
dataFilter: function (res) {
var parsed = JSON.parse(res);
return { data: parsed.d };
}
},