close

[Solved] XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header Error Occurs?

get the following error XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header in javascript.

How To Solve XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header Error ?

  1. How To Solve XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header Error ?

    To Solve XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header Error “Get” request with appending headers transform to “Options” request. So Cors policy problems occur. You have to implement “Options” request to your server.

  2. XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header

    To Solve XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header Error “Get” request with appending headers transform to “Options” request. So Cors policy problems occur. You have to implement “Options” request to your server.

Solution 1

Target server must allowed cross-origin request. In order to allow it through express, simply handle http options request :

app.options('/url...', function(req, res, next){
   res.header('Access-Control-Allow-Origin', "*");
   res.header('Access-Control-Allow-Methods', 'POST');
   res.header("Access-Control-Allow-Headers", "accept, content-type");
   res.header("Access-Control-Max-Age", "1728000");
   return res.sendStatus(200);
});

Solution 2

“Get” request with appending headers transform to “Options” request. So Cors policy problems occur. You have to implement “Options” request to your server.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment