dongmin4052 2018-07-05 08:52
浏览 108

回应没有用axios带回数据

I have a function in php, that returns the json_encoded version of a string, but when I console.log the response gotten from the json_encoded data in my react app, through axios, the data is usually empty,usually like this,Object {data: "", status: 200, statusText: "OK", headers: Object, config: Object…} ,Please what may be the issue

PHP FILE

header("Access-Control-Allow-Origin: *");
return json_encode("works");

React file

import axios from 'axios';
class LoginComponent extends Component {
componentDidMount() {
    axios.get('http://localhost/login.php')
        .then(response => {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        })
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大