Follow @endyourif rss Facebook LinkedIn

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

Published on Jun 15, 2022

Are you confused why you are getting this error? This error is caused when you are trying to perform an AJAX call from one site to a different site. Because Javascript is a client-side application it requires additional security to help protect the users from malicious code, e.g. calling a different site without the user knowing.



To solve this problem you need to install CORS on the website you're making the call TO not FROM. You then configure CORS to allow the site you are calling FROM to be a valid URL. I've provided a detailed explanation of Solving No Access-Control-Allow-Origin with Node js and Express

What is CORS?

The best way to describe this is a quote from Wikipedia: "Cross-origin resource sharing is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. A web page may freely embed cross-origin images, stylesheets, scripts, iframes, and videos."

StackOverFlow has an incredible list of questions on how to enable CORS basically for any type of server-side code and even browser.

Tags: AJAX | JavaScript | cors

My Books
ASP.NET MVC 5 With Bootstrap and Knockout.js
Knockout.js Building Dynamic Client-Side Applications
20 Recipes for Programming MVC 3
20 Recipes for Programming PhoneGap
Rapid Application Development with CakePHP