【发布时间】:2020-08-30 17:15:24
【问题描述】:
你能帮帮我吗~
我正在尝试在节点 js 上使用 json webtoken 并调用 post 方法来设置数据。
节点js服务器上的代码:
app.use(bodyParser.raw({ type: 'application/jwt' }));
代码前端调用:
$.ajax({
url: '/setSession',
type: 'POST',
Accept : 'application/json',
//contentType: 'application/json',
dataType: 'json',
data: { "hello": templateName},
//data: JSON.stringify({ "hello": templateName}),
headers: {
'Authorization': 'Bearer '+ token
},
success: function (result) {console.log('post ok'+JSON.stringify(result));
// CallBack(result);
},
error: function (error) { console.log('post failed'+JSON.stringify(error));
}
});
但是调用post请求时req.body为空或者{},我尝试了bodyparser,或者dataType但是没有成功
【问题讨论】: