0
    React Code:

    const response = await fetch("../componentsunused/testingphp.php", {

      headers: {
        "Content-Type": "application/json" // request content type
      }
      
    });
    console.log("myResponse:" + JSON.stringify(response))

    this.setState({ items: await response.json() });

    PHP Code:

    $arr = array('a' => "123");

    echo json_encode($arr);

myResponse in console always comes out as an empty array. I checked and the request went through and was returned okay. What is wrong? Thank you very much for your help.

7
  • Try console.log(response.data) Commented Feb 9, 2022 at 19:21
  • Now I have another problem: the ajax call is returning the entire php file! Commented Feb 9, 2022 at 19:55
  • You meaning it is return the content of the PHP file instead of executing and returning the results? Commented Feb 9, 2022 at 20:00
  • Yes. I have no idea why. I tried ob_get_clean and everything else but to no avail. Commented Feb 9, 2022 at 20:05
  • Are you sure you started the script with <?php? Commented Feb 9, 2022 at 20:06

0

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.