I want to fetch json from my subdomain (File Hosting Server) , but it gets the following error:
Reason: CORS request did not succeed)
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing
my similar code:
JavaScript
x
11
11
1
async function getData(url = '', data = {}) {
2
const response = await fetch(url, {
3
method: 'get',
4
mode: 'no-cors',
5
headers: {
6
'Access-Control-Allow-Origin' : '*'
7
},
8
});
9
return response.json();
10
}
11
I add
JavaScript
1
3
1
headers: {
2
} 'Access-Control-Allow-Origin' : '*'
3
but don’t work.
I add
JavaScript
1
2
1
mode: no-cors
2
to code, fetch file but return response status 0 , mode: ‘opaque’.
please help me.
Advertisement
Answer
CORS is configured through server-side, so you need to configure on your File Hosting Server