Method or type POST not posting, returns GET
Method or type POST not posting, returns GET

This is my current code which I down-scaled to bare minimum to try and get ajax to post and not get -
var ims_data_table = $('#all_parts').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url" : "../includes/ims_table_process.php",
"type" : "POST"
}
});
I have changed type to method, I have tried with and without quotes, double quotes and none. The url does get to my php page where I am dumping values. When I try $_GET, I receive a single localhost ID return value. When I try $_POST, my array is empty. When I looked in my Network, it shows that the Request Method is GET. There are many such posts but I have tried all of their fixes, still only receives a GET.
This obviously interferes with my data query which means nothing is returned.
Thank you again for assisting, much appreciated.
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
You can use the browser's Network Inspector tool with this Server Side Processing with POST example and see, in the Header tab, that a POST request is sent.
What do you see with your page? If you see a GET request then we will need a link to your page or a test case replicating the issue to help debug.
Kevin
Thank you for prompt reply Kevin, much appreciated.
My apologies around the code block, will pay attention to this.
As per my post, my browser Network shows Request Method: GET, I have checked with every change of code, it stayed on GET. Many solutions pointed me in this direction, hence my check there.
How would I load a test case/what is required for a test case?
Thank you.
@Kevin, I recreated the page with basic functions, please have a look - https://bid4anything.com/ims_test_page.php
You will see that ims_test_page shows GET in browser network whilst ims_table_process shows POST.
I also left a var_dump on values, you will see that nothing is dumped on POST. It will also throw the invalid Json error because half of code is removed.
I hope this helps.
Further to the above, code I used -
```
<script type="text/javascript" language="javascript">
$ = jQuery;
</body>
</html>
``````
php - ims_table_process.php
Yes, that is expected that the browser will use GET for the URL typed into the browser. The
"type" : "POST"
won't affect this. It only controls the request type for the Ajax request which, as you mentioned, isPOST
.I might not understand your question but the initial request for
ims_test_page.php
is outside of Datatables control. Maybe you can find what you need on Stack Overflow maybe something like this thread.Kevin
Thank you again for reply,
Sorry, I disagree, the test page has everything to do with the datatables as it hosts the table with all of its features. As per my original post, when I use type : post, it does not post but shows get in browser network. This causes that length and start is not posted and err to undefined index, to my table_process page where I can actually get the data and show it in the table on the test page.
Please check the link above for clarification if you don't mind, thanks.
Your test page is using POST for the Ajax request to
ims_table_process.php
as configured:However note that this does not control the request type for fetching the page (ims_test_page.php) which is using request type of GET:
You can see the request (
ims_table_process.php
) parameters in the Headers tab at the bottom. You can see it has the start, length and all the other parameters documented in the Server Side Processing docs:This is the response, which is not a valid JSON strong:
Your server side script is where the debugging needs to take place. The client side is working as expected.
I'm don't use PHP but I see this in your script:
var_dump($_POST['start']." testing length left, start right ".$_POST['length']);
Looks like that is what you are returning: "0 testing length left, start right 10"
Seems like the
start
andlength
values are there.I'm not sure why the response is as above instead of the records from your DB. Are you using Datatables provided server side scripts?
Kevin
Hi Kevin,
Thank you very much, I know now where to search for the fix. I was using server side scripts but it did not work for my needs so I did my own php, I know, re-inventing the wheel...
The error seems to be created on this line of code -
$query .= "LIMIT ".$_POST['start'].", ".$_POST['length']."";
Thank you again, this is much appreciated. I learned something today, look in the header responses as well for clues!
The string(37) part is just the var-dump to see what is returned by php, what is funny is that your has returned the values 0 and 10 "0 testing length left, start right 10", just tried on my side and nothing was returned, grrr. I will mark this as solved though as I know where to look though.