Skip to content
All articles

AJAX web development: requests, interface states and accessible feedback

Website source code photographed on a screen
Photo by Digital Buggu on Pexels

AJAX web development lets a page request information and update part of its interface while the visitor continues working. Use it for a clear interaction, such as checking an item or filtering a list, and design the waiting, empty and failure states alongside the successful result. A request that completes is only the beginning of a reliable feature.

For a business owner, the useful question is what the customer can do more easily. A stock lookup might avoid reloading a whole catalogue. A booking interface might refresh available choices. Neither example establishes that inventory is reserved or that a booking is confirmed: those are separate business actions that need their own rules and evidence.

How does an AJAX request work?

The browser sends a request, the service responds, and the interface interprets the result. Modern JavaScript commonly uses the Fetch API for this request-and-response work. MDN’s Fetch guide explains its promise-based model and the response methods used to read returned information.

Separate three concerns in the implementation: whether the request completed, whether the service accepted it, and whether its data has the shape the feature expects. These checks answer different questions. An HTTP response can arrive successfully while reporting a missing resource; readable JSON can still contain an unsuitable value.

Keep the business decision separate too. A positive availability response might be suitable for displaying an option, while final allocation still requires a server-side action. Write that boundary into the feature brief so that the interface does not imply an outcome it cannot establish.

Which interface states should be specified?

Use this original state sheet when briefing the interaction. The descriptions are proposed acceptance conditions, rather than findings from a customer installation.

State What the visitor should understand Question for the delivery team
Ready What information is needed and what the action does Is the control clearly labelled?
Waiting The request is in progress Does the page prevent an accidental conflicting action?
Result The relevant response is available Does the displayed information match the latest request?
Empty The request worked but found no suitable result Is this distinct from a technical failure?
Failed The requested information could not be established Is there an understandable recovery route?
Replaced or cancelled A previous request no longer owns the screen Can an older response overwrite the visitor’s newer choice?

For a search box, “no matching items” and “the service could not be reached” should not become the same message. The former tells someone to change the search; the latter may require trying again or using another contact route. Give the operator enough diagnostic information to investigate without exposing internal error details to visitors.

What does a small request boundary look like?

The following original JavaScript example deliberately receives its request function as an argument. That makes the response boundary testable without contacting a live business system. The URL and expected fields are illustrative; they are not an existing Spout endpoint or a ready-made inventory integration.

async function readAvailability(fetcher, url, signal) {
  const response = await fetcher(url, { signal });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const data = await response.json();
  if (typeof data.item !== 'string' || typeof data.available !== 'boolean') {
    throw new Error('Unexpected availability response');
  }
  return { item: data.item, available: data.available };
}

The caller still needs to catch errors, present the right state and decide which request is current. The function also does not authenticate a person, reserve stock, validate every possible business field or write anything into the page. Those responsibilities belong in the surrounding implementation and service design.

In an isolated Node.js v22.21.1 fixture, six synthetic cases passed: retaining a valid false availability value, rejecting HTTP 404 before reading JSON, rejecting a string where a boolean was required, propagating a simulated transport failure, propagating invalid JSON and forwarding the supplied cancellation signal. These were dependency-injected checks of this function. They were not browser, real-network, accessibility or production integration tests.

That distinction matters when assessing a demonstration. A small passing fixture establishes its recorded boundary, while a deployed feature still needs tests with its actual service, permissions, devices and users. Keep both kinds of evidence rather than promote one into proof of the other.

How should cancellation and changing input be handled?

MDN’s AbortController reference describes the controller and signal used to cancel asynchronous requests. In a search interface, cancellation is one tool for handling a visitor who changes the query before an earlier request finishes.

Also establish which request owns the displayed result. Record a current request identifier or equivalent state, and accept a response into the interface only when it still belongs to that state. This original implementation rule helps the team reason about a slow earlier search arriving after a newer one. Test that ordering deliberately; a fast demonstration rarely exposes it.

Do not treat an interface cancellation as evidence that a business action has been reversed. If a separate operation can place an order or change a record, its result must be established through the service’s actual transaction and recovery design. A read-only lookup and a committed business action require different acceptance questions.

How do visitors receive accessible feedback?

W3C’s status-message guidance explains how assistive technology can receive status updates without moving keyboard focus. It distinguishes the result list itself from brief messages about waiting, completion or an empty result.

In the feature brief, describe the visible message, its programmatic treatment and what happens to focus. Avoid relying on an animation alone to communicate progress. Ask the tester to complete the interaction using a keyboard and relevant assistive technology, and record what was actually announced. Reading the guidance is preparation for that work, not an accessibility certification.

Before handover, run the state sheet with realistic inputs, a deliberately delayed response and a failed service. Preserve the response reference and a useful diagnostic record, while excluding unnecessary personal information. Confirm that the ordinary page still explains the offer and gives the visitor a practical next step.

For the surrounding project, see Spout’s web development and online-store services. To scope an interaction, get started with the intended action, expected response, state sheet and service owner.

By Spout Team. AI-assisted drafting by Codex using linked primary documentation and the stated isolated synthetic fixture.

Make your next move.

A website, a store or a clearer digital plan. Let’s start with your business.

Start your brief