【问题标题】:Error returning a json from php to reactjs with axios使用 axios 从 php 返回 json 到 reactjs 时出错
【发布时间】:2017-02-12 19:04:19
【问题描述】:

当前代码正在处理 reactjs 并使用 0.14.2 版本的 axios 执行 ajax 请求:

    componentWillMount(){

    const peticion = this;
    const config = { 
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                        transformRequest: [function (data) { return data; }],
                        transformResponse: [function (data) { return data; }],
                        //responseType: 'json'
                    };

    axios.get('procesos/lista.php', config)
    .then( function (r){

        console.log(r);

        peticion.setState({
            datos:[r.data] | []
        });
    })
    .catch(function (error) {
        console.log(error);
    });
}

我正在返回纯文本,我可以修复它。

文本而不返回它是:

【问题讨论】:

    标签: php json reactjs axios


    【解决方案1】:

    我对这个问题的解决方案是使用 webpack 并让它连续运行,我所做的是在 webpack webpack.config.js 控制台中弹出并生成 bundle.js 和准备好的 axios 完美运行并且还请求 $ .ajax。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多