0

Why is PHP saying "undefined index request"? The json format looks completely correct to me.

let json = JSON.stringify(
  { request:  "getUser" },
  { username: "test" }
);

const response = await axios.post('http://localhost/projects/serverFiles/index.php', json);

My PHP

<?php
    ini_set("log_errors", 1);

    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    
    echo print_r($_POST["request"]);
?>
    
Oblivion
  • 585
  • 2
  • 8
  • 26
  • Don't stringify the object. If you want to send as json you need to change axios content type and receive it differently in the php – charlietfl Feb 05 '22 at 18:50
  • Does this answer your question? [Axios posting params not read by $\_POST](https://stackoverflow.com/questions/41457181/axios-posting-params-not-read-by-post) – ruleboy21 Feb 05 '22 at 19:40

0 Answers0