首页 > 解决方案 > Why's my GET request becoming unidentifiable?

问题描述

I want to eventually call functions from my php file onto my reactjs project so just to scratch the surface, I'm trying to to do a basic get request, but in the console, all I see is:

Here's it is [object Response] 

Which isn't what I want to happen.

What am I doing wrong and how can I fix it?

Here's my js code:

import React, { Component } from 'react';

class Home extends Component {

    componentWillMount() {
        fetch("http://localhost/myProject/phpCalls/index.php", {
            method: 'GET'
        })
            .then(res => {
                console.log("Here's it is " + res);
            });
    }

    render() {
        return (
            <h1>testing</h1>
        );
    }
}

export default Home;

Here's my php file:

header('Content-Type: application/json');

function hey() {
    echo "Will I see this?";
}

$test = $_GET['do'];

if($test === "hey") {
    hey();
}

标签: javascriptphpreactjsdebuggingget

解决方案


推荐阅读