Ich benutze Fetch in React Native, um einen Aufruf an meine API zu machen, jedoch funktioniert es nur 75% der Zeit. Wenn meine Anfrage ich nicht funktioniert bekommen dies:Fetch mit reactive native
TypeError: Network request failed
oder
SyntaxError: Unexpected token < in JSON at position 0
fetch('http://localhost/vision.php', {
method: 'POST',
headers: {
'Accept': 'application.json',
'Content-Type': 'application.json',
},
body: JSON.stringify({
key: 'Mon paramètre'
})
})
.then((data) => data.json())
.then((dataJson) => {
console.log(dataJson.message);
})
.catch((error) => {
console.log(error);
});
}
Jemand das erklären kann?
Wenn Sie "if (dataJson! == null) {..." nach dieser Zeile: ".then ((dataJson) => {", es ist immer noch passiert? –