I want to use a Real Time Prices API at https://api.idexonline.com/RealTimePrices/Calculator
And here is my function to fetch the API:
async function handleSubmit() {
try {
const res = await fetch(
`http://www.idexonline.com/DPService.asp?SID=4wp7go123jqtkdyd5f2e&cut=${shape}&carat=${carat}&color=${color}&clarity=${clarity}&make=${cut}&cert=${gradingLab}`,
{ mode: "no-cors" }
);
if (!res.ok) {
throw new Error(`Error fetching data: ${res.status}`);
}
const data = await res.json();
console.log(data);
return data;
} catch (error) {
console.error("Error: ", error);
}
}
When I’m not using mode: “no-cors” this error was logged:
Access to fetch at ‘http://www.idexonline.com/DPService.asp?SID=4wp7go123jqtkdyd5f2e&cut=ASSCHER&carat=0&color=J&clarity=VVS2&make=GOOD&cert=GIA’ from origin ‘http://localhost:5173’ has been blocked by CORS policy: The ‘Access-Control-Allow-Origin’ header contains the invalid value ‘.‘. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.*
And when I’m using mode: “no-cors” this error was logged:
Error: Error fetching data: 0
at handleSubmit