Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the principle and use of Ajax

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you the content of sample analysis on the principle and use of Ajax. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Ajax principle

AJAX means "Asynchronous Javascript And XML" (asynchronous JavaScript and XML), and AJAX is not a new programming language, but a technology for creating better, faster and more interactive Web applications. It is a set of browser-side web page development technology which integrates a number of technologies. These technologies include Javascript, XHTML and CSS, DOM, XML and XMLHttpRequest.

By exchanging a small amount of data between the browser and the server, AJAX can update web pages asynchronously. This means that some part of the page can be updated without reloading the entire page.

Advantages:

The biggest advantage of using Ajax is that you can maintain data without updating the entire page. This allows Web applications to respond more quickly to user actions and avoids sending html code messages that have not changed over the network.

1. Lighten the burden on the server and obtain data as needed.

two。 Update the page without refreshing, reducing the actual and psychological waiting time for users.

3. Better user experience.

4. Lighten the burden of broadband.

5. Supported by mainstream browsers.

Disadvantages:

1. AJAX makes extensive use of Javascript and AJAX engines, and programs that use AJAX must test compatibility for each browser.

2. When AJAX updates the content of the page, it does not refresh the entire page, so the back function of the page is invalid.

3. Poor support for search engines.

The principle of Ajax is simply to send asynchronous requests to the server and receive the response data of the server through the browser's javascript object XmlHttpRequest (Ajax engine) object, and then use javascript to manipulate the DOM to update the page. The most critical step is to get the request data from the server. That is, the user's request is sent indirectly through the Ajax engine rather than directly through the browser, and the Ajax engine also receives the response data returned by the server, so it will not cause all the pages on the browser to refresh.

For example:

The traditional way: the browser sends the request to the back end, the back end response data to the front end, the browser receives the data, renders the page, and the browser needs to "refresh".

Ajax mode: the browser creates the ajax object, the ajax object sends the request to the back end, the back end receives the request response data to the front end, and the ajax object receives the response data to update the view through dom operation. The whole process browser "does not refresh".

The real request is made by the Ajax engine. It is not emitted by the browser window, so the browser window is not refreshed, and the Ajax engine also receives the response content returned by the server.

The Ajax engine is the XMLHttpRequest object, and all modern browsers support XMLHttpRequest objects (IE5 and IE6 use ActiveXObject). It is also a Javascript object.

Ajax engine (XMLHttpRequest) is the core of Ajax integrated technology, which acts as a bridge between browser pages and servers.

Usually Javascript listens for browser web page events (clicks, submissions, changes, etc.), and Javascript creates Ajax engine objects and makes requests through Ajax engine objects. The Ajax engine waits and receives the response content of the server, and the Javascript obtains the response content from the Ajax engine object and changes the display effect of the web interface.

Non-IE browsers and advanced IE browsers: var obj=new XMLHttpRequest ()

An earlier version of IE browser: var obj=new ActiveXObject ("Microsoft.XMLHTTP")

Methods:

Abort

Cancel the current request

GetAllResponseHeaders

Get all http headers of the response

GetResponseHeader

Gets the specified http header from the response information

Open (mode get/post,url address, synchronous and asynchronous)

Create a new http request, open the request, and specify the method, URL, and authentication information (username / password) for the request

Thank you for reading! This is the end of this article on "sample Analysis of the principle and use of Ajax". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report