简体   繁体   English

CORS标头“ Access-Control-Allow-Origin”丢失,但它出现在标头中

[英]CORS header 'Access-Control-Allow-Origin' missing but it present in the header

I need read to read remote content. 我需要阅读才能阅读远程内容。 I read that should be send header Access-Control-Allow-Origin . 我读到应该发送标头Access-Control-Allow-Origin I did that but still get this error. 我做到了,但仍然收到此错误。 Here is script code 这是脚本代码

        $.ajax({
            url:'http://bbc.co.uk',
            headers: {'Access-Control-Allow-Origin': '*'},
            success:function(json){
                // do stuff with json (in this case an array)
                alert("Success");
            },
            error:function(){
                alert("Error");
            }
        });

I see Access-Control-Allow-Origin in the sent headers. 我在发送的标头中看到Access-Control-Allow-Origin。 What is wrong? 怎么了?

You should be getting this error: 您应该收到此错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。

It says that the header is missing from the requested resource, which is what you get in the response . 它说请求的资源中缺少标头,这是您在响应中得到的。

You are putting it in the request , where it does nothing useful. 您将其放在request中 ,在此没有任何作用。 Your JavaScript can't give itself permission to access other servers. 您的JavaScript无法授予自己访问其他服务器的权限。 The server you are trying to access has to give you permission. 您尝试访问的服务器必须授予您权限。

You must have ` 你必须有`

headers: {'Access-Control-Allow-Origin': '*'},

in PHP file. 在PHP文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CORS所请求的资源上没有“ Access-Control-Allow-Origin”标头 - CORS No 'Access-Control-Allow-Origin' header is present on the requested resource Web API 2 CORS不存在“ Access-Control-Allow-Origin”标头 - web api 2 CORS No 'Access-Control-Allow-Origin' header is present CORS“没有'Access-Control-Allow-Origin'标题存在”但是有 - CORS “No 'Access-Control-Allow-Origin' header is present” yet there is CORS-不存在“ Access-Control-Allow-Origin”标头 - CORS - No 'Access-Control-Allow-Origin' header is present 缺少CORS标头'Access-Control-Allow-Origin' - The CORS Header 'Access-Control-Allow-Origin' is missing (原因:CORS标头“ Access-Control-Allow-Origin”缺失) - (Reason: CORS header ‘Access-Control-Allow-Origin’ missing) JavaScript:缺少 CORS 标头“Access-Control-Allow-Origin” - JavaScript: CORS header 'Access-Control-Allow-Origin' missing 标题CORS“Access-Control-Allow-Origin”缺少Codeigniter - header CORS “Access-Control-Allow-Origin” missing Codeigniter Apache:缺少CORS标题“Access-Control-Allow-Origin” - Apache : CORS header 'Access-Control-Allow-Origin' missing CORS标题'Access-Control-Allow-Origin'缺少Cordova - CORS header 'Access-Control-Allow-Origin' missing Cordova
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM