Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

koa路由this.redirect跳转报错,有碰到类似问题的同学吗

$
0
0

代码如下,这是一个登录页,

router.post('/login', function*(next) {
    const body = this.request.body
    const username = body.username
    const password = body.password
    const info = yield user.findOne({ username, password })
    this.set('connection', 1111)
    log(this.request.header)
    log(this.response)
    if (info && info.password === password) {
      this.redirect('/home')
    } else {
      this.body = {
        status: -1,
        msg: '账号密码错误'
      }
    }
  })
总是报错:
login:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Viewing all articles
Browse latest Browse all 14821

Trending Articles