Is the page reloading before this completes due to async? This can happen in some callbacks that don't return false
.
In your code, since resp.json()
is async, the function the fetch is in will return before the fetch completes, but it will have enough time to start the fetch. If this is in an 'onSubmit' for example, if the function returns a non-false value, the page reloads, interrupting your fetch. When the first then
is encountered (which is async as well), it errors.
To fix,
<form onsubmit="myFunctionWithFetch(); return false;">
... or return false in your function and do ...
<form onsubmit="return myFunctionWithFetch();">
url
set to?resp.status
log?fetch()
should only reach.catch()
if a network error occurs. Is your server active and accepting requests? Are you requesting the correct URL? Can you include server type and configuration at text of Question?