I am using fetch to post data on backend. Every time, it is success but sometimes it caught error The data was posted but still error is shown.
I am fetching by code : - Compose.js
fetch(`${props.url}/addBalance`, {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
},
body: JSON.stringify(obj)
})
.then(resp => resp.json())
.then(res =>{
if(res) alert('Added Successfully');
else alert('Failed,Try Again');
}).catch(err=> {console.log(err);alert(err)});
}
The CORS is enabled in backend and working (checked by POSTMAN).
Success:- Success Caught Error :- without ACAO with ACAO
I run the fetch command in console and it worked fine but not in my React js App
Catch is logging error but still data is being posting
Error:- TypeError: Failed to fetch