[英]Why is html route not working in express.js?
所以这是一个非常微不足道的问题......我的客户端代码中有一个 get 请求。
function tosurvey(){$.get( "/survey", d=>d?console.log("Redirected"):false);}
和后面的听众
router.get('/survey', function(req, res) {
res.sendFile('survey.html', { root: path.join(__dirname, '../public') });
});
但是,它不起作用。 如果您直接转到 /survey,它确实有效,但是 get 请求也指向 /survey,并且应该在 onclick 上发生,因为它绑定到前面的 click 事件。
这修复了它。
let x = window.location.pathname;
x=x.split("/");
x.pop();
x=x.join('/');
$.get("/", d=>d?(console.log("Redirected"),window.location=x+'/'):false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.