I am new to react js please see below my post API call in react
updateData = datas => {
axios
.post("http://localhost:8080/ReactAPI/post.php", datas)
.then(function(body) {
console.log(body);
})
.catch(function(error) {
console.log(error);
});
}
and PHP file post.php code given below:
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, X-Requested-With");
print_r($_POST);
?>
console i give response body just like given below:
{data: "Array↵(↵)↵", status: 200, statusText: "OK", headers: {…}, config: {…}, …}
I pass datas
given below to i aspect in response
{id: "41", userId: "3672367892", fullName: "Subhash Patel"}
Please help me out here how to recieve the datas
response in post.php file
You can't get json POST data by $_POST variable. Please use following:
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With