When a search page goes blank after you click Load, there are a few plausible explanations. The request may still be running. The search may have found nothing. Or the service may have failed before it could look. The page can tell you which one happened.
Start by showing a loading message. Then check the HTTP status, read the JSON, and verify its shape. A valid list with rows gets displayed. A valid list with zero rows gets an empty message. An HTTP 503 gets an error and a way to retry, even if the server sends an empty array. The examples below use one message and one list, with no packages or build step. You just need Node.js and a browser with Fetch and JavaScript module support.
Define what counts as an empty result
The demo endpoint supplies a list of item names. ["Pencil","Ruler"] gives the page two rows, and [] gives it none. If another endpoint sends {"items":[]}, the demo rejects that response because it expects an array at the top level. Use your own endpoint’s documented shape when you adapt the example. Choosing what counts as empty gets much easier once you know what a successful response looks like.
Here’s what the same screen can say as the request moves along.
-
- Loading: “Loading items…” tells the reader that a request started.
-
- Data: Show the rows and announce the count, such as “Loaded 2 items.”
-
- Empty: “No items found.” For a filtered list, tell the reader what they can change, such as clearing a category or trying a broader search.
-
- Error: “Could not load items. Try again.” Keep the load control available once the request is over.

Before the user clicks anything, the demo says “Choose a demo endpoint.” That is the starting instruction. If your own page loads its list on arrival, start the request as soon as the page initializes and let “Loading items…” be the first status the reader sees.
Turn the HTTP response into a screen state
Save the request and state logic as items.mjs. Reading it from the call site helps. loadItems shows the pending message, waits for getItems to check the response and body, then renders what present supplies. The pending message stays on screen while the body is still being read. The renderer gets a message, a list of rows, and a flag to say whether the page is busy.
export async function getItems(url, fetcher = fetch) {
let response;
try {
response = await fetcher(url);
} catch (error) {
return { kind: "error", cause: "network" };
}
if (!response.ok) {
return { kind: "error", cause: "http", status: response.status };
}
let value;
try {
value = await response.json();
} catch (error) {
return { kind: "error", cause: "body" };
}
if (!Array.isArray(value) || !value.every(item => typeof item === "string")) {
return { kind: "error", cause: "shape" };
}
return value.length ? { kind: "data", items: value } : { kind: "empty" };
}
export function present(state) {
switch (state.kind) {
case "loading":
return { message: "Loading items…", items: [], busy: true };
case "data": {
const count = state.items.length;
const noun = count === 1 ? "item" : "items";
return { message: `Loaded ${count} ${noun}.`, items: state.items, busy: false };
}
case "empty":
return { message: "No items found.", items: [], busy: false };
case "error":
return { message: "Could not load items. Try again.", items: [], busy: false };
default:
throw new Error(`Unknown state: ${state.kind}`);
}
}
export async function loadItems(url, render, fetcher = fetch) {
render(present({ kind: "loading" }));
const state = await getItems(url, fetcher);
render(present(state));
return state;
}
There are three steps you can inspect separately when something goes wrong. fetch() can reject before it gives you a usable response. If it resolves, it response.ok tells you whether the status is in the 200–299 range. Then response.json() reads and parses the body and can still fail. Check the array only after those steps. See the Fetch guide’s status check and the Response.json() exceptions for the underlying behavior.
The same retry message works for a site visitor who gets a 503 or a response with the wrong shape. For you, those two cases call for different checks. Follow the HTTP status back to the request that failed, or compare the returned fields with what your interface expects. The demo labels a rejected Fetch request network. A browser policy can also cause a request to reject, so open DevTools before telling the visitor their connection is at fault.
Make a separate decision about HTTP 204
A 204 response has no body. It can be a successful response under another contract, but this list promises JSON, so reading a 204 as JSON fails the body step. If your API deliberately uses 204 to mean an empty list, add if (response.status === 204) return { kind: "empty" }; after the status check and before response.json(). Keep this decision specific to that endpoint. It does not make an unexpectedly blank 200 a valid result. CyboGeek’s guide to empty and incomplete Fetch bodies walks through that boundary in more detail.
Add one visible status message and a list
Save this as index.html in the same folder. It includes a selector for the test requests and a button that uses the currently selected endpoint. The module updates the page without a framework.
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fetch list state demo</title>
<h1>Fetch list state demo</h1>
<label for="scenario">Demo endpoint</label>
<select id="scenario">
<option value="slow">Slow success</option>
<option value="empty">Empty array</option>
<option value="unavailable">HTTP 503</option>
<option value="broken">Broken JSON</option>
<option value="mismatch">Wrong JSON shape</option>
<option value="no-content">HTTP 204</option>
</select>
<button id="load" type="button">Load items</button>
<p id="message" role="status" aria-atomic="true">Choose a demo endpoint.</p>
<ul id="items" aria-busy="false"></ul>
<script type="module">
import { loadItems } from "./items.mjs";
const select = document.querySelector("#scenario");
const button = document.querySelector("#load");
const message = document.querySelector("#message");
const list = document.querySelector("#items");
let busy = false;
function render(view) {
busy = view.busy;
button.setAttribute("aria-disabled", String(busy));
select.disabled = busy;
message.textContent = view.message;
list.replaceChildren(...view.items.map(item => {
const row = document.createElement("li");
row.textContent = item;
return row;
}));
list.setAttribute("aria-busy", String(busy));
}
button.addEventListener("click", async () => {
if (busy) return;
const result = await loadItems(`/api/${select.value}`, render);
if (result.kind === "error") {
console.info("List request failed:", result.cause, result.status ?? "");
}
});
</script>
</html>
Keep the status paragraph on the page from the start. Updating its text makes the new message visible and lets assistive technology pick up the change through role="status". The paragraph sits outside the busy list, which lets “Loading items…” be announced while the rows are still changing. The W3C status-message technique explains how a status can be communicated without moving focus. Try it in the screen reader and browser combinations you support.
If you start the request from the keyboard, focus can stay on the button. The aria-disabled attribute communicates that the button is unavailable while the request is in progress. The busy check in its handler is what prevents a second request. After the result arrives, that same button can be used again. The returned names go into list items throughtextContent, which displays them as text.
Start the fixture and try the outcomes
Save the server below as serve.mjs. From the folder holding all three files, run node serve.mjs and open http://127.0.0.1:8000. The sample binds to the local machine and serves the page and its fake API from the same origin. Opening index.html from a file picker won’t start those API routes. If another local app uses port 8000, stop the other app or change the port in .listen() and open the matching address. Press Ctrl+C in the server terminal when you finish.

import { createServer } from "node:http";
import { readFile } from "node:fs/promises";
import { pathToFileURL } from "node:url";
const here = new URL("./", import.meta.url);
export function createDemoServer() {
return createServer(async (req, res) => {
const path = new URL(req.url, "http://127.0.0.1").pathname;
const routes = {
"/": ["index.html", "text/html; charset=utf-8"],
"/items.mjs": ["items.mjs", "text/javascript; charset=utf-8"],
};
if (Object.hasOwn(routes, path)) {
const [file, contentType] = routes[path];
try {
res.writeHead(200, { "content-type": contentType });
res.end(await readFile(new URL(file, here)));
} catch {
res.destroy();
}
return;
}
res.setHeader("content-type", "application/json; charset=utf-8");
res.setHeader("cache-control", "no-store");
switch (path) {
case "/api/slow":
setTimeout(() => res.end('["Pencil","Ruler"]'), 800);
break;
case "/api/empty":
res.end("[]");
break;
case "/api/unavailable":
res.statusCode = 503;
res.end('{"error":"unavailable"}');
break;
case "/api/broken":
res.end('["Pencil"');
break;
case "/api/mismatch":
res.end('{"items":[]}');
break;
case "/api/no-content":
res.statusCode = 204;
res.end();
break;
default:
res.statusCode = 404;
res.end('{"error":"unknown case"}');
}
});
}
const launchedAsScript = process.argv[1] &&
import.meta.url === pathToFileURL(process.argv[1]).href;
if (launchedAsScript) {
createDemoServer().listen(8000, "127.0.0.1", () => {
console.log("Open http://127.0.0.1:8000");
});
}
Start with Slow success. The status changes immediately when you press Load items. The fixture waits roughly eight-tenths of a second before responding, so you get time to see the loading message. It then reports “Loaded 2 items.” and adds Pencil and Ruler to the list. Pick Empty array next and press the same button. The result reads “No items found.” and the old rows disappear.
Next, choose HTTP 503, Broken JSON, and Wrong JSON shape one at a time. All three end with “Could not load items. Try again.” The browser console identifies which step failed. An error screen with a retry path is useful even when the failure belongs to the server. Open the Network panel when you need to see which request returned 503 or which 200 body had an unexpected format.
If your own endpoint always lands on the failure message, find that request in the Network panel and check the final URL. A development server can send its usual HTML page when the API route is missing. You’ll see a 200, but the JSON reader will reject that body. If the body is JSON and the console reports a shape error, check what the outermost value is. A list inside an items field needs different handling from a list returned by itself. Fix that at the point where you read the response so the rendering code can keep working with the same input.
An automated check using Node.js v22.23.5 ran against these local endpoints. It asserted that the first render was the loading message and the second render matched the expected message and rows. The eight cases included delayed data, an empty array, HTTP 503, invalid JSON, wrong shape, 204, 404, and a connection failure. This verifies the messages passed into the renderer. Live announcements can vary with the browser and assistive technology.
Adjust repeat requests and updates for your interface
Keep a successful list visible during a refresh
The sample clears its list on every request so you can see each case independently. Think about what happens on a dashboard that refreshes the same list every few minutes. The last set of rows is still useful while the next copy loads. Keep those rows in a refresh state and show “Updating items…” above them. If the refresh fails, leave them in place and tell the user the update failed. When someone applies a new filter instead, mark the old rows as previous results or clear them so they can tell which search they’re looking at.
Let a new search replace a slow one
A dashboard button can use the one-request rule in this demo. A search field with a request per query needs a different rule. If a slow search for “pen” completes after a newer search for “pencil,” the old response could repaint the screen. Give the latest request an identifier and compare it before rendering any result. An AbortController can also cancel a prior request, and replacement-triggered cancellation should quietly leave the new search in charge. If you add cancellation, change the broad rejection branch to recognize intentional aborts rather than displaying an error for each superseded search. See CyboGeek’s stale Fetch request example for that workflow.
Keep retry behaviour proportionate to the request
The example loads a read-only list. The button runs another GET and gives the reader control over when to make that request. A repeated click will rarely help if the service and client disagree about the response format, so preserve the status or cause in developer diagnostics. Automatic retries add more traffic when a service is already slow. Choose them deliberately for temporary failures and pick an upper bound before enabling them. A write operation has different consequences from a list request and needs its own retry policy.
Check what a person can actually recover from
Run the slow, empty, and error cases on a narrow screen. Check that the message stays visible without requiring a horizontal scroll, the load button still has a clear focus indicator, and a user can reach it again after an error. If you decide to add an icon or spinner, keep the status in words as well. Test an empty result immediately after a successful result to catch stale rows, and test success immediately after an error to catch a leftover warning.
If you also run Fetch on the server, use the CyboGeek Node Fetch migration fixture to check runtime behavior such as cancellation and response body handling. Start your screen check with an ordinary trip through the list. Load it, change the filter so it returns nothing, then try a failed request and recover from it. At each step, the message above the list should explain what has happened and leave you able to make the next choice.
