Javascript navigator.sendBeacon数据发送到服务器
我正在尝试收集数据并将其发布到服务器,但是 当我试图发布JSON.stringify(JSON数组)时,在服务器端我没有收到帖子 如果im只发送json数组,那么im将获得post(无法解析它) 我找了很多东西想找到答案, 尝试使用cors。。。 例如:Javascript navigator.sendBeacon数据发送到服务器,javascript,json,performance,server,Javascript,Json,Performance,Server,我正在尝试收集数据并将其发布到服务器,但是 当我试图发布JSON.stringify(JSON数组)时,在服务器端我没有收到帖子 如果im只发送json数组,那么im将获得post(无法解析它) 我找了很多东西想找到答案, 尝试使用cors。。。 例如: var customParser = bodyParser.json({type: function(req) { return req.headers['Content-Type'] === '*/*; charset=UTF-8'
var customParser = bodyParser.json({type: function(req) {
return req.headers['Content-Type'] === '*/*; charset=UTF-8';
}});
app.post('/rum', customParser, function(req, res){
console.log(req.body);
console.log(JSON.parse(req.body));
ramData.addData(JSON.parse(req.body), function (err, res) {});
});
任何帮助?暂时禁用sendBeacon内容类型-未捕获的DomeException:无法在“导航器”上执行“sendBeacon”:暂时禁用带有Blob的sendBeacon(),该Blob的类型不是内容类型请求标头的任何CORS safelisted值。有关详细信息,请参阅
var customParser = bodyParser.json({type: function(req) {
return req.headers['Content-Type'] === '*/*; charset=UTF-8';
}});
app.post('/rum', customParser, function(req, res){
console.log(req.body);
console.log(JSON.parse(req.body));
ramData.addData(JSON.parse(req.body), function (err, res) {});
});