0

i try to send data (PersonName) from vue axios request to php script but git this error in php file :


Warning: Undefined array key "Person" in C:\xampp\htdocs\linktree-vue\linktree-Create-Page.php on line 7
null

i tried follwoing :

         const Pagedata = {
                Person: "Youmna",
            };

            const options = {
                method: 'POST',
                url: 'http://localhost/linktree-vue/linktree-Create-Page.php',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                data: Pagedata
            };

            axios.request(options)
                .then(response => {
                
                    console.log(response.data);
                })
                .catch(error => {
                    console.error(error);
                });

php file (linktree-Create-Page.php) :

header('Content-Type: application/json');
header("Access-Control-Allow-Origin: http://localhost:8080");
// Allow any domain to access the API
header("Access-Control-Allow-Origin: *");

$PersonName = $_POST['Person'];
print_r($PersonName);
echo json_encode($PersonName);
?>

Note : files pathes is correct, the request in f12 window is giving response 200 (success request) .. but doesnot read my data

  • did not understand . can u make it clearer, sur ? – Ahmed Khaled El-Dakhly Mar 13 '23 at 16:27
  • To begin with, use `print_r($_POST)` then you can see exactly what php thinks is there in the POST data – ADyson Mar 13 '23 at 18:35
  • But basically axios is sending the data as JSON, ignoring your header. You can see this is you use your browser's network tool to see the payload. Read the duplicate, it tells you what to do – ADyson Mar 13 '23 at 18:36

0 Answers0