Server-Side Processing: Send Request via JSON
Server-Side Processing: Send Request via JSON
kaseykrehbiel
Posts: 18Questions: 2Answers: 0
Using this example:
http://datatables.net/release-datatables/examples/data_sources/server_side.html
When I click the Next button on the table, the request header looks like this:
[code]
GET /release-datatables/examples/server_side/scripts/server_processing.php?sEcho=3&iColumns=5&sColumns=&iDisplayStart=20&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&_=1353960845704 HTTP/1.1
[/code]
My question is this: Is there any way built into dataTables that allows me to send this data via JSON instead of in the URL string? Something like:
[code]
{
"sEcho": "3",
"iColumns": "5",
"iDisplayStart": 20 // etc.
}
[/code]
http://datatables.net/release-datatables/examples/data_sources/server_side.html
When I click the Next button on the table, the request header looks like this:
[code]
GET /release-datatables/examples/server_side/scripts/server_processing.php?sEcho=3&iColumns=5&sColumns=&iDisplayStart=20&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&_=1353960845704 HTTP/1.1
[/code]
My question is this: Is there any way built into dataTables that allows me to send this data via JSON instead of in the URL string? Something like:
[code]
{
"sEcho": "3",
"iColumns": "5",
"iDisplayStart": 20 // etc.
}
[/code]
This discussion has been closed.
Replies
Allan
Thanks for your response. After I wrote this question, I learned that you can use POST instead of GET, and that gets me halfway there, but I'd like to be able to post JSON instead of sending the data through the query string. I don't want to send it as an HTTP parameter, but a normal string in the "responseText". (In this case it'd be the opposite of responseText as I'm sending it to the server, but the same concept nonetheless.)
What I'm trying to do overall is setup a WCF service that accepts JSON as input and returns JSON as output in order to fill up the datatable. I'm doing that everywhere else on the site I'm working on and I want to do it with this plugin as well. Does fnServerData allow me to do that?
By the way, I just want to say a huge thank you to you for all of your work on this plugin. It is absolutely awesome, and I've been using it for several years across many projects and platforms and it just gets better and better. I really appreciate it!
An HTTP parameter is a normal string. You can't send parameters over HTTP without using HTTP parameters! You must(*) do something like:
[code]
variable1 = whatever1
... etc
[/code]
You could have `whatever1` as a JSON string if you want.
(*) Actually you can just set the body of the request if you want. Have a look around Google, but I'd imagine its unlikely that you want to do that unless you are really quite sure of it, or are uploading files etc.
Allan
> That's how the response comes back, isn't it?
Yes, but the key difference is between making the request and what comes back.
Allan