chrome中的错误:Content-Type不被Access-Control-Allow-Headers所允许

尝试发送ajax请求时,Chrome中出现此错误:

Content-Type is not allowed by Access-Control-Allow-Headers 

一切工作正常在Firefox。

任何人都可以帮我解决这个问题?

我解决了添加到Apache Web Server虚拟主机configuration下面的设置的问题

 Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept" 

PHP的解决scheme:

 header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST,GET,OPTIONS'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); 

(需要在任何其他内容之前发送)

我有同样的问题,我解决了它通过添加以下头:Access-Control-Allow-Headers:content-type

在节点中设置CORS(跨站点HTTP请求)。 对我来说,看起来像下面这样:

 app.use('/api', function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type'); next(); }); 

对于我来说,即使我只设置了这个标头设置,localy也可以工作:

header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');