我正在使用REACT-JS框架进行前端开发:
下面是我在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
};
}
为了测试目的,我从其他localhost:8000
获取答案。
我遇到了以下错误:
无法加载http://localhost:8000/login:预检请求的响应未能通过访问控制检查:所请求的资源上不存在 'Access-Control-Allow-Origin' 头。因此,不允许从源头 'http://localhost:3000' 访问它。
以及error.request
的控制台日志。