The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin

39,549

You have to set Access-Control-Allow-Origin header to * or specified value http://localhost

You can do this through:

1- Your code

2- .htaccess file

3- Server config (restart web server required)

Here is the link that show how to do it on apache

http://access-control-allow-origin-guide.com/enable-cors-on-apache-linux/

Share:
39,549
Daniel R.
Author by

Daniel R.

Updated on October 06, 2021

Comments

  • Daniel R.
    Daniel R. over 2 years

    I am trying to login with ajax to an API and I get this error:

    XMLHttpRequest cannot load. The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin. Origin 'http://localhost' is therefore not allowed access.

    I read all about this error, all over the internet, and I've tried all the solutions I could find online. I modified the .htaccess and apache httpd configuration file according to the CORS instructions here: http://enable-cors.org/server_apache.html

    Access-Control-Allow-Origin: *
    

    Nothing seems to be working. I'd really appreciate if you guys can help me out with this. Thank you!

  • Daniel R.
    Daniel R. almost 8 years
    Thank you for your comment, but I couldn't find any way to do this. Finally, I decided to use curl instead of ajax.
  • salt
    salt about 3 years
    It is not insecure to set Access-Control-Allow-Origin header to *?