Home > Web Front-end > JS Tutorial > XMLHttpRequest object properties and the advantages and disadvantages of ajax

XMLHttpRequest object properties and the advantages and disadvantages of ajax

php中世界最好的语言
Release: 2018-06-04 11:05:20
Original
1823 people have browsed it

This time I will bring you the XMLHttpRequest object attributes and the advantages and disadvantages of ajax. What are the precautions for using the XMLHttpRequest object attributes and the advantages and disadvantages of ajax. The following is a practical case, let's take a look.

The XMLHttpRequest object has three important attributes:

onreadystatechange state change

eventtrigger, this will be triggered every time the state changesEvent handler

readyState changes from 0 to 4

0 = Not initialized

1 =Loading/server connection established

2 =Loaded/Request received

3 =Interacting/Request processing

4 =Request completed

statusHTTP of the server

Status code:

1 prefix: message. This type of status code means that the request has been accepted and needs to continue processing.

2 prefix: success. This type of status code means that the request has been successfully received, understood, and accepted by the server. (200:'OK')

3 prefix: redirect. This type of status code indicates that the client needs to take further action to complete the request. (304:'Not Modified')

4 prefix: Request error. This type of status code represents that an error may have occurred on the client, which is hindering the server's processing.

5, 6 Prefix: Server error. This type of status code represents an error or abnormal state in the process of processing the request by the server.

Advantages of Ajax

Updating data without refreshing

The biggest advantage of AJAX is that it can update the entire file without refreshing it. Communicate with the server to maintain data on the premise of the page. This allows web applications to respond to user interactions more quickly and avoids sending unchanged information over the network, reducing user waiting time and bringing a very good user experience.

Asynchronous communication with the server;

AJAX uses an asynchronous method to communicate with the server, without interrupting the user's operation, and has a faster response capability. Optimizes the communication between Browser and Server, reducing unnecessary data transmission, time and data traffic on the network.

Front-end and back-end load balancing

AJAX can transfer some of the work previously burdened by the server to the client, using the client's idle capabilities to process it, reducing the burden on the server and bandwidth, saving space and bandwidth rental cost.
And reduce the burden on the server, the principle of AJAX is to "get data on demand", which can minimize the burden caused by redundant requests and responses on the server and improve site performance

Widely supported based on standards :

AJAX is based on standardized and widely supported technology. It does not require downloading browser plug-ins or applets, but requires the customer to allow
JavaScript to be executed on the browser. As Ajax matures, some program libraries that simplify the use of Ajax have also come out. Likewise, another assistive programming technology has emerged to provide alternative functionality for users who do not support JavaScript.

Separation of interface and application:

Ajax separates the interface and application in the WEB (it can also be said to separate data and presentation), which is conducive to division of labor and cooperation and reduces WEB applications caused by non-technical personnel's modification of the page. Program errors, improved efficiency, and more suitable for the current
release system.

Disadvantages of Ajax

AJAX kills the history function, which is the destruction of the browser mechanism:
In the case of dynamically updating the page, the user cannot return to the previous page state, because the browser can only remember the static page in the history record . The difference between a page that has been completely read and a page that has been dynamically modified is very subtle;
Users will usually expect that clicking the back button will cancel their previous operation, but in an Ajax application, this will not be possible.
Those who have used Gmail know that the Ajax technology used under Gmail solves this problem. You can go back under Gmail'.
However, it cannot change the Ajax mechanism. It is just a relatively stupid one. But an effective way is to reproduce the changes on the page by creating or using a hidden IFRAME when the user clicks the back button to access the history. A related point is that using dynamic page updates makes it difficult for users to save a specific state to favorites. Solutions to this problem have also emerged, most of which use URL fragment identifiers (often called anchors, the part after the # in the URL) to keep track,
allows the user to return to a specified application state. (Many browsers allow JavaScript to dynamically update anchors, which allows Ajax applications to update anchors while updating the displayed content.) These solutions also solve many of the arguments about not supporting the back button

AJAX Security issues:

AJAX technology not only brings a good user experience to users, but also brings new security threats to IT companies. Ajax technology is like establishing a direct channel for enterprise data. This allows developers to inadvertently expose more data and server logic than before.
Ajax logic can be hidden from client-side security scanning technology, allowing hackers to create new attacks from remote servers. Ajax is also difficult to avoid some known security weaknesses, such as cross-site scripting attacks, SQL injection attacks, and Credentials-based security vulnerabilities.

Weak support for search engines:

Weak support for search engines. If used improperly, AJAX will increase network data traffic, thereby reducing the performance of the entire system.

Based on standards and widely supported:

AJAX is based on standardized and widely supported technology. There is no need to download browser plug-ins or small programs, but the customer needs to allow JavaScript to be executed on the browser. As Ajax matures, some program libraries that simplify the use of Ajax have also come out. Likewise, another assistive programming technology has emerged to provide alternative functionality for users who do not support JavaScript.

AJAX does not support mobile devices very well:

Some handheld devices (such as mobile phones, PDAs, etc.) do not yet support Ajax very well. For example, when we open a browser using Ajax technology on a mobile phone, website, it is currently not supported.

The client is too fat, and too much client code causes development costs

It is complex to write and error-prone; there are many redundant codes (it is a common problem of AJAX to include js files in layers, plus. A lot of server-side code in the past is now placed on the client); destroying the original standards of the Web.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

The core of Ajax’s working principle and objects

The use of Polyfill annotations and preventing modifications in JS

The above is the detailed content of XMLHttpRequest object properties and the advantages and disadvantages 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