Hi,
Bạn nào có thể giải thích giúp ko ? trong reactjs mình gặp lỗi này khi lấy dữ liệu api.
Access to XMLHttpRequest at ‘https://dev.ghtk.vn/services/shipment/fee?address=P.503%20tòa%20nhà%20Auu%20Việt,%20số%201%20Lê%20Đức%20Thọ&province=Hà%20Nội&district=Quận%20Cầu%20Giấy&pick_province=Hà%20Nội&pick_district=Quận%20Hai%20Bà%20Trưng&weight=1000’ from origin ‘http://localhost:3005’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
code:
axios.post( url, {}, {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
"Token": Constants.API_GHTK.API_TOKEN_KEY,
"X-Requested-With": "XMLHttpRequest",
// "Host": "dev.ghtk.vn"
},
"async": true,
"crossDomain": true,
}).then(function (response) {
console.log('response is 5 : ' + response.data);
}).catch(function (error) {
if (error.response) {
console.log("4:", error.response.headers);
}
else if (error.request) {
console.log("1: ", error.request);
}
else {
console.log("2: ", error.message);
}
console.log("3: ", error.config);
});
}