AJAX Post no longer works when using DataTables
AJAX Post no longer works when using DataTables
MoeYehya
Posts: 16Questions: 9Answers: 0
Are we able to make a post request instead of get inside ajax datatables generate method?
_ const url = ${AppRuntime.baseUrl}/${props.entity}/Table/False?${$.param(requestBody)}
;
var table = window.$(#table${props.tableId}
).DataTable({
"ajax": {
"url": url,
"type": "POST", // Change request type to POST_
Answers
Yes it can be used. The
ajax
docs state this:The
type
will be passed through to jQuery ajax().Use the browser's network inspector tool to see the XHR request and response.
Kevin
okay but when it was a get request i was adding some quert parameters like this : var table = $(
#table
).DataTable({"ajax": {
"url": AppRuntime.baseUrl + '/' + props.entity + '/Table/' + (props.datasource ? props.datasource : ""),
"type": "GET",
"data": {
"id": 0,
"inputVal": "",
"queryParameters[0]": props.queryParameters ? props.queryParameters[0] : []
},
now it becomes post request and i am sending different thing in data (body).
_ how i can add extra query parameters for it?
_
Take a look at the
ajax.data
docs and this example for sending data parameters.Kevin
can you please tell me if there is anything wrong in this?
Nothing that I can see. Does it show work for you? In what way is it not working? What is
props.queryParameters[0]
? If you link to a test case showing the issue, that might help us help you.Is unusual, but it isn't used in the above code, so irrelevant.
Allan
this is not the problem.. the request is returning not found. the query parameters that should be filled by datatables is not showing in url when we changed it to post request.
but it is working completely fine in get request.
is it something in datatables?
When sending data using GET the data is sent in the URL. When sending data via POST the data is not sent in the URL but in a header in the AJAX request. This is standard jQuery ajax() protocol not Datatables specific. You will need to review the documentation for your server side language to learn how to process POST data as it will be different.
Use the browser's network inspector tool to verify the data parameters sent are correct.
Kevin