简体   繁体   中英

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 . 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. What is wrong?

You should be getting this error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

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. Your JavaScript can't give itself permission to access other servers. The server you are trying to access has to give you permission.

You must have `

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

in PHP file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM