账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    koa处理xhr请求,服务端能接受并顺利处理,但chorme显示xhr.status=404,浏览器无法接收response
    44
    0

    xhr请求,koa处理,服务端能接受并顺利处理,但无法返回response,xhr.status=404,但将路由里的代码从向MongoDB获取数据 换成 简单的赋值返回,则一切正常,xhr.status=200.如下图,如果换成注释内的代码,则正常执行

    route.post('/login',async function(ctx,next){

    var userauth=function () {
         userModel.find({name: ctx.request.body.username}, function (err, user) {
            if (err) {
                throw err;
            }
            if (user.length == 0) {
                console.log(typeof(user));
                console.log(user.length == 0);
                console.log('user not register');
                return "user not register";
            }
    
            else {
                userModel.find({
                    name: ctx.request.body.username,
                    password: ctx.request.body.password
                }, function (err, user) {
                    console.log(ctx.request.body.username);
                    console.log(ctx.request.body.password);
                    console.log(user);
                    if (err) {
                        throw err;
                    }
                    console.log("user:" + user)
                    if (user == null || user.length == 0) {
                        console.log(user);
                        console.log('password wrong');
                        ctx.response.body = "login fail";
                        return "login fail";
                    }
                    if (user != null && user.length > 0) {
                        console.log('login sccessful');
                        ctx.response.body = "login successful";
                        return "login successful";
                    }
                })
            }
    
        })
    }
    var response=await userath();
    return response;
    
    /*var initial={ username:"suki",password:'123456'};
    console.log(ctx.request.body);
    console.log(ctx.request.body.username);
    console.log(ctx.request.body.password);
    if(ctx.request.body.username==initial.username){
        console.log("登录成功");
        ctx.response.body="login successful";
        //return response;
    }
    else {
        console.log("登录失败");
        ctx.response.body="login fail";
    }
    console.log("post login end");*/

    })

    请问是为什么?以及解决方法。谢谢你们啦~~

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • @夢姼 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部