Follow one fetch out and back: when it resolves, when it rejects, where a 404 goes, and what you hold after await fetch(). An interactive Fetch: modern…
Almost every page gets its data through fetch. The two costliest misunderstandings: thinking a 404 lands in catch, and forgetting that reading the body waits too. Knowing the shape of the exchange lets you handle network errors, HTTP errors and parsing errors one by one.
fetch only rejects when there is no reply at all
await fetch() does not throw for a 404 fetch only rejects when there is no reply at all (network down, CORS). For 4xx/5xx, check if (!res.ok) throw new Error(...) yourself.res.json() must be awaited too fetch is two stages: await fetch() gives the Response (status, headers), then await res.json() reads its body. Without the second await you hold a Promise, not the data.$.ajax fetch is built into every modern browser. A library of about 30 KB for one feature you already have is not worth it.body body: { isi } is sent as the text "[object Object]". Turn it into JSON first with JSON.stringify(...) and set Content-Type: application/json.res step Press → until the parcel is home. res already has its status and headers, but its body is not read yet.res.ok check off The gudang answers 404, fetch still resolves, and tampil shows undefined without a single error.res.json() on an HTML page An address without /api is answered 200 with HTML. res.ok passes, res.json() is what throws a SyntaxError.