node.js - nodejs redirect failure problem
PHPz
PHPz 2017-06-06 09:53:14
0
1
1293

1. After sending the superagent request, process the data in the background, and then choose whether to redirect based on the results but it always fails.
2. The code is as follows:

//superagent请求
 request.get(`/allStudios`)
                .end((err,res) =>{
                    next({type:'ALL_STUDIOS',content:res.body})
                });
//后台处理
router.get('/allStudios',(req,res,next)=>{
    Studios.find({},(err,data)=>{
        if(req.headers.cookie){
            res.send(data);
        }
        else {
            res.redirect(302,'http://localhost:3000');
        }
    })
});

3. The result is that there is no way to implement redirection

Please help me solve it, thank you!

PHPz
PHPz

学习是最好的投资!

reply all(1)
给我你的怀抱

ajax cannot be redirected, but you can make your own judgment after getting the data at the front end. If you need to redirect, use window.location.href = 'new address' to jump.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template