小编Yug*_*pte的帖子

TypeError:JSON.stringify(...).then 不是一个函数 - React JS

我正在尝试将我的反应应用程序与登录页面的后端连接。我正在使用承诺返回成功消息。

登录.js

    onSubmitSignIn = () => {
        fetch('http://localhost:5000/', {
              method : 'post',
              headers :{ 'Content-Type' : 'application/json'},
              body : JSON.stringify({
                   userId : this.state.userId,
                   password : this.state.password
             }).then(response => response.json())
               .then(data => {
                    if(data === 'success'){
                            this.props.onRouteChange('home');
                    }
             })
        })
    }
Run Code Online (Sandbox Code Playgroud)

后端代码-

  exports.findById = (req) => {
         return new Promise((resolve) => {
               var sql = "Select * from users where userid = '" + req.body.userId + "' ;";
               connection.query(sql,req,  function (error, results, fields) {
                    var data = JSON.parse(JSON.stringify(results)); 
                    var valid = …
Run Code Online (Sandbox Code Playgroud)

json express reactjs

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

express ×1

json ×1

reactjs ×1