I'm learning ReactJS. I'm using fetch
for getting data from an API. I used below code for it.
fetch('http://myurl.com/api')
.then(res => res.json())
.then(res => console.log(res));
The API is hitting with status 200 ok
but in response Nothing to Preview and in console getting below error
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://myurl.com/api with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
I also added headers in below code.
fetch("http://xxx.xxx.xxx.xxx:8081/api/category/popular",{
method: 'GET',
headers: {
'Access-Control-Allow-Origin': '*',
},
})
I have below json in API response
{
"data":[
{
"parent_id":"5c2f74e0a4d846591b2b1a40",
"icon":"http://myurl.in:8081/default.png",
"_id":"5c2f74e8a4d846591b2b1a41",
"name":"Shop",
"modified_at":"2019-01-04T14:59:52.791Z",
"created_at":"2019-01-04T14:59:52.791Z"
},
{
"parent_id":"5c2f74e0a4d846591b2b1a40",
"icon":"http://myurl.in:8081/default.png",
"_id":"5c2f7566a4d846591b2b1a42",
"name":"Home Service",
"modified_at":"2019-01-04T15:01:58.507Z",
"created_at":"2019-01-04T15:01:58.507Z"
},
{
"parent_id":"5c2f74e0a4d846591b2b1a40",
"icon":"http://myurl.in:8081/default.png",
"_id":"5c5c2dd30d017c401ec17253",
"name":"Test",
"modified_at":"2019-02-07T13:08:35.653Z",
"created_at":"2019-02-07T13:08:35.653Z",
"__v":0
}
]
}