简体   繁体   中英

how to log datas from form tags on nodejs server-side?

<form action="/signupOk" method="post" class ="signupForm">
  <input type="text" name="id" placeholder="." class ="name" required><br>
  <input type="password" name="password" placeholder="" required><br>
  <input type="text" name="nickname" placeholder="" required><br>
  <input type="email" name="nickname" placeholder="" required><br>
  <input type="tel" name="nickname" placeholder="" required><br>
  <input type="address" name="nickname" placeholder="" required><br>
  <input type ="text" name="code" placeholder=""><br>
  <input type ="submit" value ="hi"/>
</form>

This is front-side code

var express = require('express');
var nodeCmd = require('node-cmd');
var fs = require("fs");
var path = require('path');
var favicon = require('serve-favicon');
var app = express(); 
var server = require('http').createServer(app); 
var bodyParser = require('body-parser');
var request = require('request');
app.use(bodyParser.json()); 
app.use(express.static(__dirname + '/public')); // 
app.use(favicon(__dirname + '/0101c_icon.ico')); 
var port = 1010; 
var AppStart = function() { console.log(''); }
server.listen(port, AppStart); 

And I'll skip some codes about sever starting.

// signup
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.static(path.join(__dirname,'public')));

app.post('/signupOk', function(req, res){
  var id = req.param("id");
   console.log(id);
 });

And this is the codes to send datas from form tags to database. But I wanna know were datas moved ok right here correctly. I cannot use alert, and about using console.log, After submit, Broswer is refreshed so console log is clean. How can I check datas arrived there correctly? Thanks.

Four input fields in your form have the same name. That probably isn't helping things.

'body-parser' puts your form field values into 'req.body' . 'req.params' is for route parameters (slugs in the url path.).

So, try 'console.log(req.body);' to see the parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM