JavaScript AJAX Interview Questions and Answers

Understand asynchronous browser requests and the client-server patterns historically described as AJAX.

Frequently Asked Questions

Important questions are highlighted in the sections below; select one to jump to its answer.

Theoretical JavaScript Interview Questions

AJAX (Asynchronous JavaScript and XML) is a technique for making asynchronous HTTP requests from a browser to a server without reloading the entire page. It enables dynamic content updates. Modern implementations use JSON rather than XML, and the Fetch API or XMLHttpRequest to make requests.

Client-side JavaScript can send a request asynchronously, wait for the response, and update the relevant DOM elements. The browser remains on the current document while the request is in flight; the code still needs to handle loading, success, and failure states.

AJAX means Asynchronous JavaScript and XML, a technique for exchanging data with a server without a full-page navigation. Modern applications commonly use JSON rather than XML.

XMLHttpRequest is a browser API for making HTTP requests from JavaScript. Despite its name, it can send and receive formats such as JSON, text, and binary data.

An asynchronous request lets JavaScript continue responding to user input while the browser waits for the network. The result is handled later instead of blocking the page.

After the request completes, inspect its HTTP status, commonly checking for a 2xx response. A completed request is not necessarily successful; a 404 response is also complete.

Parse response text with JSON.parse, or use a response API such as fetch().json(). Handle parsing failures when malformed server data is possible.

Cross-Origin Resource Sharing lets a server specify whether browser code from another origin may read its response. Client-side JavaScript cannot override a missing server permission.

An HTTP error is a received response with an unsuccessful status, such as 404 or 500. A network error means the browser could not complete or expose the request, for example because of connectivity or CORS.

fetch is promise-based and composes naturally with async/await, while XMLHttpRequest uses events and exposes upload progress conveniently. fetch usually fulfills for HTTP error statuses, so callers must check response.ok or status.

For some cross-origin requests, the browser first sends OPTIONS to ask whether the method and headers are allowed. The server must authorize them before the browser sends the actual request.

Cross-origin credentials require an explicit fetch credentials mode, and the server must return a specific allowed origin plus Access-Control-Allow-Credentials: true. A wildcard origin is invalid for credentialed access.

Pass an AbortSignal to fetch, then call abort() on its AbortController. The promise rejects with an abort-related error that can be handled separately from other failures.

Retry transient failures only, bound attempts, use exponential backoff with jitter, and respect Retry-After. Retrying non-idempotent operations can duplicate effects unless the API supports idempotency.

A server can return an ETag and a later request can send it in If-None-Match. If unchanged, the server may reply 304 so the cached body can be reused.