Cannot POST form node.js - express

后端 未结 3 1563
抹茶落季
抹茶落季 2020-12-05 07:26

Using express 3.1.0 I have a super simple form:

相关标签:
3条回答
  • 2020-12-05 07:49

    Your example works for me. I removed the references to User, user, and routes so that I can run it and the HTTP POST is received and displayed correctly in the console.

    app.post('/signup', function(req, res) {
        var username = req.body.username;
        var password = req.body.password;
        console.log("post received: %s %s", username, password);
    });
    

    I suspect the error is in your User.addUser() code.

    0 讨论(0)
  • 2020-12-05 07:54
    router.route('/signup')
    
        // (accessed at POST http://localhost:3000/api/signup)
        .post(function(req, res) {
            var username = req.body.username;
            var password = req.body.password;
            res.json(
                { 
                   message: 'signup success',
                    username : username,
                     password : password,
                }
            );
        })
        .get(function(req,res){
            res.json({message: 'get request from signup'});
    });
    
    // REGISTER OUR ROUTES -------------------------------
    // all of our routes will be prefixed with /api
    app.use('/api', router);
    
    0 讨论(0)
  • 2020-12-05 08:02

    You can write something like this:

    action="http://localhost:3000/sin"
    
    0 讨论(0)
提交回复
热议问题