如何将res发送回我的目录中的本地html文件

时间:2018-02-20 08:29:37

标签: express

此代码来自我目录中的本地html文件, 如何发送回html文件,res.send(“ok”)

 app.post('/', (req, res) => {
   let data = {
    name: req.body.name,
    email: req.body.email,
    pass: req.body.pass,
    contact: req.body.ccontact
   }
  const action = req.body.action;
  if (action == "submit") {

 req.checkBody("name", "Enter a valid name  address.").notEmpty()
 req.checkBody("email", "Enter a valid email address.").isEmail()
 req.checkBody("pass", "Enter valid password address.").isAlphanumeric()
 req.checkBody("contact", "Enter valid address.").notEmpty().isNumeric()

    let error = req.validationErrors()
    if (error) {

        console.log(error)
       res.send("ok")
    }

1 个答案:

答案 0 :(得分:0)

尝试简单地将res.send("ok")移出if检查错误,因为现在只有在出现错误时才会发送回复:

 app.post('/', (req, res) => {


let data = {
    name: req.body.name,
    email: req.body.email,
    pass: req.body.pass,
    contact: req.body.ccontact
   }
  const action = req.body.action;
  if (action == "submit") {

 req.checkBody("name", "Enter a valid name  address.").notEmpty()
 req.checkBody("email", "Enter a valid email address.").isEmail()
 req.checkBody("pass", "Enter valid password address.").isAlphanumeric()
 req.checkBody("contact", "Enter valid address.").notEmpty().isNumeric()

    let error = req.validationErrors()
    if (error) {

        console.log(error)   
    }
 res.send("ok");