mongodb - express中插入数据库后不能跳转
某草草
某草草 2017-05-02 09:22:26
0
2
546
exports.adduser = function(db) {
    return function(req, res) {
        // Get our form values. These rely on the "name" attributes
        var userName = req.body.username;
        var userEmail = req.body.useremail;
        var collection = db.get('users');
        var llll = collection.insert({
            "userid": userName,
            "password": userEmail,
        })
        if (llll) {
            res.location('http://baidu.com');
        } else {
            res.send("error")
        }
    }
};

数据库是插入成功的,但是不会正确跳转至到百度
报错是 500 TypeError: res.location is not a function

这是什么原因?

某草草
某草草

reply all(2)
Ty80

Just checked it out, res.location是设置locationRequesting the header

res.location('/foo/bar');
res.location('foo/bar');
res.location('http://example.com');
res.location('../login');
res.location('back');

can be used with res.redirect()里相同的urls.

For example, if your program root address is /blog, 下面的代码会把 location 请求头设置为/blog/admin:

res.location('admin');

Here are the key points

Generally, backend jumps are made using res.redirect([status], url), (status is optional, default is 302):

res.redirect('/foo/bar');
res.redirect('http://example.com');
res.redirect(301, 'http://example.com');
伊谢尔伦

Look at how you call this method. It may be that res is not passed in correctly

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!