I want to fetch data from an HTTP request(Witch I created in Spring Boot), but I am getting this error:
Unhandled Rejection (TypeError): Failed to fetch
This is my code:
const getData=()=>{
fetch('http://localhost:8080/data'
,{
headers : {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
)
.then(function(response){
console.log(response)
return response.json();
});
}
useEffect(()=>{
getData()
},[])
}