表单不在节点js中提交

时间:2017-01-24 15:19:14

标签: node.js express body-parser

当我提交表格时,没有任何事情发生。 没有错误。 当我使用服务器代码进行ajax调用时它工作正常,但它不能正常工作。 这是我正在使用的简单html表单。 我的main.js文件在节点js上。 请帮帮我。

<!DOCTYPE html>
            <html>
              <head>
                <meta charset="utf-8">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <meta http-equiv="x-ua-compatible" content="ie=edge">
                <title></title>

                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
              </head>
              <body>
                <nav class="navbar navbar-default">
              <div class="container-fluid">
                <div class="navbar-header">
                  <a class="navbar-brand" href="/">TRAIL APP</a>
                </div>
                <ul class="nav navbar-nav">
                  <li class="active"><a href="/">Home</a></li>
                  <li><a href="Page1">Page 1</a></li>
                  <li><a href="Page2">Page 2</a></li>
                </ul>
              </div>
            </nav>
            <div class="form-group" method='post' action='/user'>
              <label for="usr">Name:</label>
              <input type="text" class="form-control" id="usr" name="username">
            </div>
            <div class="form-group">
              <label for="pwd">Password:</label>
              <input type="password" class="form-control" id="pwd">
            </div>
                <input type="submit" value="SUBMIT" class="btn-primary" id='select_link' >


                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">



                </script>
                <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" ></script>
              </body>
                <script
              src="https://code.jquery.com/jquery-3.1.1.min.js"
              integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
              crossorigin="anonymous">
      </script>

我的快递节点代码是:

var http = require("http");
    var fs=require('fs');
    var express =require('express');
    var  app =express();
    var bodyParser = require('body-parser');
    app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies


    app.get('/', function (req, response) {
      var file= fs.createReadStream(__dirname+'/index.html');

      file.pipe(response);
    })
    app.get('/Page1', function (req, response) {
      var file= fs.createReadStream(__dirname+'/Page1.html');

      file.pipe(response);
      console.log("FIRST PAGE");
    })
    app.get('/Page2', function (req, response) {
      var file= fs.createReadStream(__dirname+'/Page2.html');

      file.pipe(response);
      console.log("SECOND PAGE");});


      app.post('/user', function (req, response) {
        if (!req.body) return response.sendStatus(400)
    console.log(req.body.username) })

    app.listen(3000, function () {
      console.log('Example app listening on port 3000!')
    })

0 个答案:

没有答案