search

Home  >  Q&A  >  body text

node.js - 问个问题 Uncaught (in promise)

是这个样子的
vue+vue-resource+express组合
然后在下面这里遇到问题了

client

this.$http.jsonp('http://localhost:3300/register', { params: { name: this.name, password: this.password, repassword: this.repassword } }, {})
          .then(function (response) {
            console.log(response.data.state)
          })

server

app.get('/register', function (req, res) {     
            userTools.create(user).then(function(result){
                res.jsonp(result)
            }).catch(function(err){
                res.jsonp(data)
            })
    })

这样就会出错

如果server改为下面这样就不出包错了

app.get('/register', function (req, res) {     
     res.jsonp(data)
     }

这是问什么啊?

大家讲道理大家讲道理2787 days ago347

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:18:10

    First of all, I agree with the opinion above, I also think it is an error reported by the server

    Judging from the error picture, the first error is due to the jsonp request initiated by the poster, but the response header set when returning is set to 'application/json'. The poster can understand the principle of jsonp and try to call res.setHeaders in get. (It seems that I can’t remember this API clearly. In short, it just sets the response header). Try changing the mine type of the response data to 'application/javascript'

    Secondly, the Uncaught (in promise) error refers to an error when calling promise. It is a subsequent error caused by the first error, but the client does not catch it. The author can write like this

    this.$http.jsonp('http://localhost:3300/register', { params: { name: this.name, password: this.password, repassword: this.repassword } }, {})
              .then(function (response) {
                console.log(response.data.state)
              }).catch(e => {
                  // 打印一下错误
                  console.log(e)
              })

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:18:10

    There should be a problem with the sever code. Check to see if there is an error in the server part

    reply
    0
  • Cancelreply