Server-side processing - is it possible to send data as JSON instead of URL params?
Server-side processing - is it possible to send data as JSON instead of URL params?
Out of the box, it looks like server-side processing will generate ajax calls that may look like this:
?draw=1&columns[0][data]=someColumnXYZ&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false
I'm interested in whether this information can be sent as JSON instead for easier processing on server side. For reference, I am looking to process these with a Java backend (Spring MVC). Having to parse this information manually seems quite inelegant. Is there a better way?
This question has accepted answers - jump to:
Answers
Hi @PIKSTANG ,
Yep, if you use POST data, that will do it. See the example here.
Cheers,
Colin
Hi @colin,
Thanks for the example. I gave it a try and found the default format is still sending as form data
application/x-www-form-urlencoded
. I ended up adding"contentType" : "application/json"
as well as wrapping the data insideJSON.stringify()
in order for it to be recognized as proper JSON data on the backend.Not sure if I'm on the right track here as these are modifications I had to make inside the DataTables library. Any suggestions for making this work without modifying
jquery.dataTables.js
? To clarify, mainly I'm concerned about having to wrap the data insideJSON.stringify()
.Thanks,
Pik
See if
ajax.data
will work for you. Something like the last example in the docs.Kevin
Yup - what Kevin suggests sounds like exactly what you want. The last example shows how you can have the data send as JSON in the request body.
Allan
Perfect! Thanks everyone
When sending data like this , the pagination parameteres are not working, like start , limit and sort. Any solution for this ?
Please don't duplicate questions. See my response in your other thread.
Kevin