Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to resolve No 'Access-Control-Allow-Origin' header is present on the requested resource

As I am running following set of the code

  1. AngularJS enter image description here
  2. HTML

html code 3. Error

enter image description here

like image 787
Sikandar Sahab Avatar asked Jan 27 '26 04:01

Sikandar Sahab


2 Answers

Installing above mentioned plugin for chrome is not a permanent solution for your issue and you cannot ask the end user to do the same.

Best way to do is to handle it in your api code.

There are plenty of resources available to see how it is configured for various languages api. The following link will make you to understand about it and how to configure.

Why does my JavaScript get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when Postman does not?

like image 181
Sajeetharan Avatar answered Jan 28 '26 21:01

Sajeetharan


You can try below plugin in chrome browser: Core extension

And if you want to add on server side then on server you can add below headers (for PHP add this in index.php)

header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE, PUT');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With, X-CLIENT-ID, X-CLIENT-SECRET');
header('Access-Control-Allow-Credentials: true');
like image 39
Binit Ghetiya Avatar answered Jan 28 '26 20:01

Binit Ghetiya