Home > Web Front-end > JS Tutorial > Briefly talk about the core objects of AJAX

Briefly talk about the core objects of AJAX

亚连
Release: 2018-05-24 14:33:56
Original
2314 people have browsed it

The core object is XMLHttpRequest, which can update web pages without reloading the page. After the page is loaded, the client requests data from the server. After the page is loaded, the server receives data and sends data to the client in the background. .

Ajax is a new technology that was only born in February 2005 but is already very popular. This new technology can greatly improve the user experience of the website.

What is Ajax

Ajax is the English abbreviation of Asynchronous JavaScript and XML.

The core concept of Ajax is to use the XMLHttpRequest object to send asynchronous requests. Ajax is not a new language Or technology, it is actually a combination of several technologies in a certain way, playing their respective roles in joint collaboration.

Advantages of Ajax

1. Reduce the burden on the server. The principle of Ajax is "fetch data on demand".

2. No need to refresh the page, reducing user psychology and actual waiting time.

3. Bring better User experience.

 4. Some of the work previously burdened by the server can be transferred to the client, using the idle capacity of the client to process, reducing the burden on the server, making full use of broadband resources, saving space and broadband rental costs.

  5. Can call external data.

  6. Based on standardized and widely supported technology, no need to download plug-ins or small programs.

  7. Further promote page rendering Separate from data.

2. Introduction to XMLHttpRequest object

One of the biggest features of Ajax is that it can transmit or read and write data to the server without refreshing the page (also known as Refresh the update page), this feature mainly benefits from the XMLHTTP component XMLHttpRequest object.

Properties

Description

onreadystatechange

This event handler will be triggered every time the state changes, usually calling a JavaScript function
readyState Requested state
responseText The server's response is expressed as a string
responseXML The server's response is expressed as XML, This object can be parsed into a DOM object
status The HTTP status of the server
statusText Corresponding text of HTTP status

This event handler will be triggered every time the state changes, usually calling a JavaScript function

XMLHttpRequest method

Some commonly used methods of the XMLHttpRequest object

Method Description
abort() Stop the current request
getAllResponseHeaders() Return all corresponding headers of the HTTP request as key/value pairs
getResponseHeader("header") Return the string value of the specified header
open("method","url") Create a call to the server. The method parameter can be GET, POST or PUT, etc.; the url parameter can be a relative URL or an absolute URL. This method also includes 3 optional parameters
send(content) Send a request to the server
setRequestHeader("header","value") Set the specified header to the provided value. The open() method must be called before setting any header

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to terminate the ajax request being sent by js and jQuery

Share three kinds of analysis of ajax Pattern

Compare three implementations of Ajax and JSON parsing

The above is the detailed content of Briefly talk about the core objects of AJAX. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template