Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  122] [ 6]  / answers: 1 / hits: 13221  / 7 Years ago, wed, december 20, 2017, 12:00:00

I´m using REACT-JS framework for FRONT-END:



This is my calling action from REDUX-REACT



export function UserLogin(values) {
var headers = {
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Content-Type': 'application/json'
}

const request = axios.post('http://localhost:8000/login', headers, values).then(function(response){
/*() => {callback();}*/
console.log(response);
})
.catch((error) => {
// Error
if (error.response) {
console.log(error.response.data);

}
else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request);
}
else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
});
return {
type: LOGIN_REQUEST_SUCCESS,
payload: request
};
}


I´m getting answer from other localhost:8000 for testing purposes.



I´m getting this errors:




Failed to load http://localhost:8000/login: Response to preflight
request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:3000' is therefore not allowed
access.




And the console log from error.request


More From » reactjs

 Answers
4

You should set 'Access-Control-Allow-Origin': '*', at server's response header.



For more details, check this answer.


[#16215] Tuesday, December 19, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monicag

Total Points: 651
Total Questions: 106
Total Answers: 104

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;