【发布时间】:2014-09-04 07:35:00
【问题描述】:
我正在尝试将一些 json 发布到运行 express 的节点服务器,但它一直告诉我 json 无效。但它不是,它只是一个普通的旧物体。目前我收到错误'unexpected token i'
客户:
$.ajax({
contentType: 'application/json',
type: "POST",
url: "/admin",
data: {id: '435ghgf545ft5345', allowed: true}
});
服务器:
var bodyParser = require('body-parser');
app.use(bodyParser({strict: false}));
app.post('/admin', function(request, response) {
console.log(request.body);
});
我还尝试将 bodyParser.json() 作为第二个参数放在 post 路由中,并得到错误 'invalid json at parse'。我不知道为什么。
【问题讨论】: