XMLHttpRequest (XHR) API
(Redirected from XMLHttpRequest)
Jump to navigation
Jump to search
A XMLHttpRequest (XHR) API is a browser-based API that allows the sending and receiving of data between a client and a server asynchronously without refreshing the web page.
- Context:
- It can send HTTP requests to a server using methods such as GET, POST, PUT, and DELETE.
- It can retrieve data from a server in various formats, including XML, JSON, HTML, and plain text.
- It can be used to enable dynamic updates to web pages by interacting with server-side resources.
- It can be implemented in conjunction with AJAX to create seamless, responsive web applications.
- It can include support for both synchronous and asynchronous operations, although asynchronous usage is recommended.
- It can handle response states through event-driven programming using the `onreadystatechange` event.
- It can manage cross-origin requests subject to CORS (Cross-Origin Resource Sharing) policies.
- ...
- Example(s):
- AJAX requests, which rely on XMLHttpRequest to fetch server-side data without refreshing the browser page.
- Form submissions, where data is sent to a server asynchronously for validation or processing.
- API calls, to consume external RESTful or SOAP services via HTTP.
- ...
- Counter-Example(s):
- Fetch API, which offers a modern alternative with improved syntax and support for promises.
- WebSocket protocol, which provides full-duplex communication instead of request-response.
- HTML form submissions, which involve page reloads and lack asynchronous capabilities.
- See: HTML Form, Application Programming Interface, JavaScript, Object-Oriented Programming, Method (Computer Programming), HTTP, Web Browser, Web Server, Ajax (Programming), Hyperlink.
References
2024
- (Wikipedia, 2024) ⇒ https://en.wikipedia.org/wiki/XMLHttpRequest Retrieved:2024-11-23.
- XMLHttpRequest (XHR) is an API in the form of a JavaScript object whose methods transmit HTTP requests from a web browser to a web server.[1] The methods allow a browser-based application to send requests to the server after page loading is complete, and receive information back.[2] XMLHttpRequest is a component of Ajax programming. Prior to Ajax, hyperlinks and form submissions were the primary mechanisms for interacting with the server, often replacing the current page with another one.[2]