The XMLHttpRequest (XHR) object is the core of AJAX. It is a built-in browser object that allows you to make HTTP requests in JavaScript without having to refresh the page.
Click the button below to trigger a real request. Watch how the readyState changes from 0 to 4 in real-time:
All modern browsers have a built-in XMLHttpRequest object.
const xhttp = new XMLHttpRequest();
| Method | Description |
|---|---|
open(method, url, async) |
Specifies the type of request. |
send() |
Sends the request to the server. |
abort() |
Cancels the current request. |
getResponseHeader() |
Returns specific header information. |
Property values change as a request progresses:
The readyState property holds the status of the XMLHttpRequest:
readyState is 4 AND status is 200 (Successful).