![](/img/trans.png)
[英]How to add my function “new page” in my index.js with cordova
[英]How to switch to a new function in index.js
我基本上在index.js中有一个router.post()函数,并且我想在该函数内调用另一个router.post()函数。 像这样:
router.post('/checkregisfields', function(req, res, next) {
var x = req.body.email;
var p = req.body.password;
var p1 = req.body.passwordagain;
console.log(x);
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
res.render('index', {title: 'nDoto', err2: 'Invalid Email Address!'});
return false;
}
if (p1!=p){
res.render('index', {title: 'nDoto', err2: 'Passwords do not match!'});
}
// If email and password are all okay, "redirect" to my other
// router.post('/regsubmit', function(req, res, next) function
// What is the syntax/command to "redirect" to another post function?
})
router.post('/regsubmit', function(req, res, next) {
});
只需将通用代码分解为可以从两个地方调用的函数:
function regsubmit(req, res, next) {
// code here
}
router.post('/regsubmit', regsubmit);
然后,您也可以从其他路由处理程序调用regsubmit(req, res, next)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.