跨域请求被阻止:同源策略禁止读取URL上的远程资源

Kor*_*rte 3 php web-applications httprequest cross-domain angularjs

这是非常著名的浏览器错误。我知道已经对此进行了很多讨论,但是我注意到这是一个非常普通的错误,因此我想介绍一下我的问题。

我正在可以访问的服务器上进行简单的请求(获取,发布)。我的浏览器(chrome,firefox)给我Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at url (Reason: CORS header 'Access-Control-Allow-Origin' does not match 'null').错误。

当我使用某些(黑客)插件时,我得到的响应很好。

我尝试过的是在后端(在服务器上)添加:

header('Access-Control-Allow-Origin: *');
Run Code Online (Sandbox Code Playgroud)

index.php文件中没有运气。还有其他想法吗?

dde*_*blo 5

尝试添加

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
Run Code Online (Sandbox Code Playgroud)