XMLHttpRequest javascript
时间: 2023-09-16 08:11:36 浏览: 42
XMLHttpRequest (XHR) is a built-in JavaScript object that allows developers to make HTTP requests to a server and receive data in various formats, such as JSON, XML, HTML, or plain text. It is used to communicate with a web server without reloading the entire page.
XHR can be used to:
- Update parts of a web page without reloading the entire page
- Submit form data asynchronously
- Retrieve data from a server and use it in a web application
- Send data to a server and receive a response without reloading the page
XHR works by creating an instance of the XMLHttpRequest object and then sending a request to a server using one of the HTTP methods, such as GET or POST. The response from the server can then be parsed and displayed on the web page.
XHR is widely used in modern web development, especially in single-page applications (SPAs), where the user interface is updated dynamically without refreshing the page.