I know this question is already there in stack overflow, but it's not relevant for my issue. I didn't get a solution.
I have two file index.html
and data.json
.
My code:
<!doctype html>
<html>
<head>
</head>
<body>
<script>
async function fun(){
const res = await fetch('temp.json');
const dat = await res.json();
return (Object.values(data));
}
console.log(fun());
</script>
</body>
</html>
{
"1": "One",
"2": "two",
"3": "Three"
}
I got the error mentioned in the title in my browser (firefox and mobile chrome). Console:
Promise { <state>: "rejected", <reason>: TypeError }
<state>: "rejected"
<reason>: TypeError: NetworkError when attempting to fetch resource.
<prototype>: Promise.prototype { … }
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/kashyap/Desktop/data.json. (Reason: CORS request not http).