I am trying to use fetch()
API POST method in order to grab the POST data in PHP.
Here is what I have tried:
var x = \"hello\";
fetch(url,{m
Appearently, when using the Fetch API to send data to a PHP server, you'll have to handle the request a little different from what you're used to.
The data you're "POSTing" or "GETting" is not going to be available in the super global variables since this input is not coming from a multipart-data form or an application/x-www-form-urlencoded
You can get your data by reading the special file: php://input
, for example using file_get_contents('php://input')
and then try to decode that input with json_decode()
.
Hopefully it helps.
You cand read more about it here:
https://codepen.io/dericksozo/post/fetch-api-json-php