“I have a website that uses an API, but when a user opens my site, it encounters a CORS error. Can you guide me on how to resolve it? I wrote it in JavaScript.”
async function fetchData(currency) {
try {
let response = await fetch(
`https://api.XXXXXX.ir/market/stats?srcCurrency=${currency}&dstCurrency=usdt`);
let data = await response.json();
let dayChange = data.stats[`${currency}-usdt`].dayChange;
let LastPrice = data.stats[`${currency}-usdt`].latest;
return {
currency,
dayChange: parseFloat(dayChange),
LastPrice
};
} catch (error) {
// console.error(`Error fetching data for ${currency}: ${error}`);
return null;
}
}
“I tried using various proxies, but it didn’t work.”
New contributor
ararai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.