6

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

1 Answer 1

6

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.