0
$.post("test=+");
服务器端:
app.post('/test', function(req, res) {
console.log(req.body.test); // Print is empty.
});
如何逃生呢?不打印像“&,+等”的符号。
$.post("test=+");
服务器端:
app.post('/test', function(req, res) {
console.log(req.body.test); // Print is empty.
});
如何逃生呢?不打印像“&,+等”的符号。
我注意到的第一件事是您试图发布到/test
,但是您没有向该网址发送键/值对。例如,发布/test=+
即使在/ test中有一个路由处理程序,也会给我一个404,因为express将请求视为'/ test = +'而不仅仅是'/ test'。
其次,你需要url编码它,而不是html编码它。这个工作对我来说:
$.post('/test', 'test=%2B');
这里是我有Express服务器上的代码:
router.post('/test', function(req, res) {
console.log(req.body);
res.send('received');
});
而且它产生:
{ test: '+' }
太谢谢你了! – owl