Ajax GET requests are working properly. But I have to use POST because I expect to send more data, too much for GET.
Environment: Apache 2, Debian 9 (from scratch), jQuery 3.2.1, nothing special.
I split my problem into this code:
CUSTOMER
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Ajaxtest</title> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> </head> <body> <script language="JavaScript"> <!-- $.ajax({ url: 'ajaxtest2.php', dataType: 'json', contentType: 'application/json; charset=utf-8', type: 'POST', data: {testdata: 'here I am'}, success: function (resp) { console.log(resp); }, }); --> </script> </body> </html>
SERVER
<?php ini_set('error_reporting', E_ERROR); header('Content-type: application/json'); header('HTTP/1.1 200 OK'); print json_encode( array( 'method'=>$_SERVER['REQUEST_METHOD'], 'get'=>$_GET['testdata'], 'post'=>$_POST['testdata']) ); exit(); ?>
When sending a call, ajax via GET only changes
type: 'POST'
to
type: 'GET'
Which gives me this result on the console:
{method: "GET", get: "here i am", post: null}
This is what you expect.
But when called through POST, I get:
{method: "POST", get: null, post: null}
The server understands the POST request, but does not pass any values.
I tried different ways to include the destination URL as someone with the same results recommended
url: 'ajaxtest2.php' url: './ajaxtest2.php' url: './ajaxtest2.php/'
They all do not matter: $ _POST remains empty.
I also ran get_defined_vars () on the server, but $ _POST remains empty, and there is no trace of 'here I am' anywhere in the resettable variables.
There is no .htaccess mixed with URL rewriting or the like.
What else can I do?