I'm trying to send data to a PHP file.
I tried adding {headers:{'content-type: application/JSON'}}
, but I still can't access the data in PHP.
Javascript:
axios.post("http://localhost/Contact_Manager/src/fetchcontacts.php",{action:'getcontacts'})
.then(res => {
let posts = res.data;
commit('setposts',posts)
})
.catch(err => console.log(err))
PHP:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
$db = mysqli_connect("localhost","root","","contacts");
if(!$db){
die("failed to connect to database".mysqli_connect_error());
}
$recieved_data=json_decode(file_get_contents("php://input"),true);
var_dump($recieved_data->action)
?>
There's a warning in the PHP file:
Notice: Trying to get property 'action' of non-object in project directory