Reputation: 452
I have a small question as follow: I have a function that it takes on values input and returns JSON string. In my function GET_PRODUCT input a parameter as string @product_name . The result as JSON , I do not know how to pass parameters in here . I must declare how do use dataSrc in here (suppose webmethod GET_PRODUCT is work with parameter input )
var table;
table = $('#div_table').DataTable({
"processing": false,
"serverSide": false,
"ajax": {
"url": "../BUS/WebService.asmx/GET_PRODUCT",
"dataType": "json",
"contentType": "application/json; charset=utf-8",
"type": "POST",
dataSrc: function (json) {
//dataSrc: function (json(Candy)) {
//transfer parameter in here
//result as JSON string will parsed and fill in DataTables
return $.parseJSON(json.d);
},
//dataSrc: "Candy",
},
I do not understand the issue pass parameters in here. Please share with me. Thank guys.
Upvotes: 0
Views: 1870
Reputation: 452
Ok, it work follow
"ajax": {
"url": "../BUS/WebService.asmx/GET_PRODUCT",
"dataType": "json",
"contentType": "application/json; charset=utf-8",
"type": "POST",
data: function (data) { return "{'product_name':'Candy'}"; },
dataSrc: function (json) { return $.parseJSON(json.d); }
},
Upvotes: 1
Reputation: 15293
You can extend the default data being send to the server by using the data parameter e.g.
"data": function ( d ) {
return $.extend( {}, d, {
"product_name": "Candy"
} );
The dataSrc parameter lets you manipulate the data that was being returned from the server. This can either be a string definining the property from the object being returned or a function which will have a single parameter, the JSON returned from the server.
"dataSrc": function ( json ) {
for ( var i=0, ien=json.length ; i<ien ; i++ ) {
// manipulate the returned data in here!
}
return json;
}
You can find more information on the ajax DataTable settings here.
Good luck.
Upvotes: 0