view raw
Apprentice Apprentice - 5 months ago 57
Javascript Question

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

I know this qquestion has asked several times but none has solved my problem.I am using axios for fetching the token from the server( I am working on localhost. I have supplied the header too but still i get an error of

No 'Access-Control-Allow-Origin' header is present
. Is this error being produced from my js code(axios) or it is a problem in server?

const config = {
method: 'get',
url: `${API_URL}/getToken`,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',

export function getToken() {
return function (dispatch) {
console.log('action triggered atleast');
.then(response => {
console.log('response', response);
dispatch({ type: GET_TOKEN });
.catch(error => {
errorHandler(dispatch, error.response, TOKEN_ERROR);

Have i done any mistake or missed something in my code?


The server need to send the back the CORS header not the request

Take a look here how to enable cors:

If you don't have access to the server then maybe you want to try something like a cors proxy