How do use pass parameter in dataSrc DataTables ?
How do use pass parameter in dataSrc DataTables ?
headshot9x
Posts: 59Questions: 16Answers: 1
Hello everybody.I have a small question as follow , I use the parameter passed dataSrc AJAX . I have a function that takes on values and returns JSON string parameter then I must declare how you use dataSrc. 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 .
"ajax": {
"url": "../BUS/WebService.asmx/GET_PRODUCT",
"dataType": "json",
"contentType": "application/json; charset=utf-8",
"type": "POST",
dataSrc: function (json) {
return $.parseJSON(json.d);
}
//dataSrc: function (json(candy)) {
// return $.parseJSON(json.d);
//}
//dataSrc: "Candy",
},
Thank you.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I try , but it is not work
Thank you.
Can you link to the page in question showing the problem so I can debug it please.
Allan
@, I try
After run , i get error
{"Message":"Invalid JSON primitive: product_name.","StackTrace":"
Dear allan . After try more time .I get
It have just worked and the result as JSON string , But it not show in DataTables. It error show at file jquery.datatable.js
I think the result should parseJSON
How do you think it ?.Thank sir
I don't really know anything about your server-side platform so I can't really give much advice about it. You can certainly do that in
ajax.data
- I don't really see why it would be needed, but if it works for your use case...Allan
As i say "I can get data" when using
but it's not show in DataTables, please, see at http://debug.datatables.net/ibexok ., you will see data , but it's not show in DataTables.
I'm so sory , i try the function orther in this case
The server is responding with a single parameter in the JSON object called
d
. I have no idea why Microsoft thought that would be a good idea, but it is nonsense!You need to use the
ajax.dataSrc
option to parse the JSON contains in that parameter and then return it. For exampleAllan