I’m using Fedora 28 and have PHP 7.2 installed on the machine. I’ve used the following command to start a local http server for testing php -s localhost:8000/
I’m able to post to php scripts which live in the directory where I start the php server using curl (curl -d foo=bar localhost:8000/somephp.php)
However, when I use a browser and javascript to do an ajax post to the script, it returns an empty array.
I get a 200 when I post to the script and I’m using very vanilla js to complete the ajax post.
Well it looks like an implementation issue, how is the javascript sending data to the server and how is the server receiving it? If it’s sending in through POST and the server is looking at GET then it’s like nothing was sent.
I’m sending the request as a post and attempting to access the $_POST variable.
The php server doesn’t appear to have trouble with receiving post (ie I can use the curl command to post to it). It only seems to occur when I use Javascript.
It appears the JS can reach the php file fine (the 200 I receive) it’s just the data isn’t being captured.
My JS is basically the following:
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
Can you give a more comprehensive fragment of your script because from what you’ve given the curl request is indeed POST but the ajax one is a GET request.