async handleSubmit(event) {
event.preventDefault();
console.log("test");
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
val1: "val1",
val2: 2
})
};
const response = await fetch(
myURL,
requestOptions
);
if (response.status >= 200 && response.status <= 299) {
const jsonResponse = await response.json();
console.log(jsonResponse);
} else {
console.log(response.status, response.statusText);
}
}
I wrote this handleSubmit
function for a form that needs to send an API request and get back some data. However, it gives the error Typeerror failed to fetch every time with no further explanation or messages. I tried error handling but still no output at all from the fetch part. What could be the reason?