正在尝试使用node.js中的express在app.get函数中获取查询
我试图在“status.html”之后获取查询,例如正在尝试使用node.js中的express在app.get函数中获取查询,node.js,express,get,Node.js,Express,Get,我试图在“status.html”之后获取查询,例如localhost:3000/status.html?channel=“我想要获取的字符串” 因此,我编写了如下代码 app.get('/status.html', isLoggedIn, function(res, req){ if (req.query.channel){ if (req.isAuthenticated()){ res.redirect('/status'); }else{ co
localhost:3000/status.html?channel=“我想要获取的字符串”
因此,我编写了如下代码
app.get('/status.html', isLoggedIn, function(res, req){
if (req.query.channel){
if (req.isAuthenticated()){
res.redirect('/status');
}else{
console.log("Please Log in to access to this webpage");
res.redirect('/login');
}
}
});
然而,它甚至没有通过app.get'/status.html'
我这里有什么问题。。。?
有人能帮我吗
多谢各位
以防万一,我的目录设置如下
node_modules
public
images
javascripts
js
stylesheets
status.html
routes
views
login
app.js
package.json
app.get(路径,回调)
是一个路由
路径可以是字符串
aa regex模式
// if you use `/status.html` then html `href` should as be same path
// `/status.html`
// app.get('/status.html', isLoggedIn, function(res, req){
app.get('/status', isLoggedIn, function(res, req){
if (req.query.channel){
if (req.isAuthenticated()){
res.redirect('/status');
}else{
console.log("Please Log in to access to this webpage");
res.redirect('/login');
}
}
});
在html文件中,您必须使用href
html文件
// <a href ="/status.html" class="btn btn-default btn-sm">Status</a>
<a href ="/status" class="btn btn-default btn-sm">Status</a>
请从您的公共目录中删除文件status.html并创建路由,它基本上是请求到您的公共目录,
如果您想在公共目录中使用status.html,可以在那里实现ajax工作。谢谢您回复我!:)陛下我懂了。。我已经从代码中设置并重定向到'localhost:3000/status.html',工作没有问题,所以我想我可以使用app.get('/status.html')东西….:'(
localhost:3000/status.html
表示您正在静态加载html文件,请查看expressres.sendFile()
函数谢谢!:)我将查看express res.sendFile()函数:)再次感谢您的帮助!谢谢你回复我!:)我如何使用ajax…?:'(
// `/status.html` is just a route path it has nothing to do with html files