'How to pass serialized form data to datatables?
I use datatables with server-side handler. Major code:
$("#dt-flats-build").dataTable({
processing: true,
serverSide: true,
ajax: {
url: "/api.json",
data: $('form#filter').serialize()
},
});
and I have a form with filter. I pass form data to the api.json as addential params.
So, I can pass only fields one by one, but not all fields from form. Do you have any ideas?
Solution 1:[1]
Check out here - https://datatables.net/examples/server_side/post.html
By default, the Ajax request that DataTables makes to obtain server-side processing data is an HTTP GET request. However, there are times when you might wish to use POST. This is very easily done by using the type option of the ajax initialisation option.
Use -
"ajax": {
url: "/api.json",
"type": "POST",
data: $('form#filter').serialize()
},
Solution 2:[2]
I'm using net core with ViewModel, which required to post with "." as form values. I have below instead, hopefully this helps anyone came across something similar.
ajax: {
url: "/api.json",
data: function (d) {
return $('form#filter').serialize() + "&" + $.param(d);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sid |
| Solution 2 | Angelicheart |
