如何解决如何使用reactjs和redux修复cors问题?
我用reactjs和redux开发了我的项目,我想在本地主机上获取我的api,我尝试:
const fetcherActivite = () => {
let _fetcher;
_fetcher = ky.extend({
prefixUrl: "https://exampledomain.com/",retry: 1,credentials: "same-origin",headers: {
"x-idc":"idc","Authorization":"test token",}
});
return _fetcher;
};
export const getListeActivite = () => {
return (dispatch,getState) => {
fetcherActivite()
.get(`api_activite/typeactivite/`)
.then(response => response.json())
.then(json => {
const activites = {liste: json.tabinfo}
dispatch(setActivites(activites));
});
}
}
运行它,我得到:
Access to fetch at 'https://exampledomain.com//api_activite/typeactivite/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
当我运行它时,它不起作用,但是,在我的服务器WINSCP domain.com上,它运行良好。
它如何在localhost上工作?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。