What is XHR?
XHR is a browser API for fetching data without reloading web pages. In practice, XHR lets JavaScript request documents from web servers so pages update in place. It is part of the web platform, used by web browsers to exchange information. Older code could still rely on it.
XMLHttpRequest Object
The core object, XMLHttpRequest, exposes methods for setup and response handling. Set method and URL, then call open and send. Headers, status, and readyState track progress; events fire. In xml contexts, documents must be well-formed and tags must follow stricter syntax; XHTML 1.0 had the strictest rules under W3C standards.
How to Send XMLHttpRequest
Typical flow has two steps. First, create a new XMLHttpRequest in JavaScript and choose the method and type of data. Keep XMLHttpRequest asynchronous by default. Second, register onload and onerror handlers, then send the action to the server software. Use HTTPS, follow web standards, consider CORS. For dynamic content or markup languages beyond HTML, xml syntax and valid elements matter.
XMLHttpRequest Example
Сreating web requests to an API. In JavaScript, you create an XHR, call open(‘GET’,’/api/items’), set headers, and send. When the response arrives, the script updates contents. This works across sites; browsers support caching. Prefer small payloads and clear errors; new markup should be minimal. XMLHttpRequest supports upload progress; XMLHttpRequest also lets you set the response type and the request type.