javeEE Week 5

1. Definition

       AndXML" (Asynchronous Javascript and XML), refers to a web development technology for creating interactive web applications. AJAX = Asynchronous JavaScript and XML (a subset of Common Markup Language), is a A technology that can update part of a web page without reloading the entire web page. By exchanging a small amount of data with the server in the background, AJAX can make the web page update asynchronously. This means that the web page can be updated without reloading the entire web page. Some parts are updated.

       Focus: (1) AJAX = Asynchronous JavaScript and XML (asynchronous JavaScript and XML).

                     (2) AJAX is not a new programming language, but a new way to use existing standards.

                     (3) AJAX is the art of exchanging data with a server and updating parts of a web page, without reloading the entire page.

2. Working principle

       

       AJAX is based on existing Internet standards and is used in combination with: XMLHttpRequest object (exchange data asynchronously with the server), JavaScript/DOM (information display/interaction), CSS (defining styles for data), XML (as a format for transforming data) . Of particular note is that AJAX applications are browser and platform independent.

3. Application Examples    

       The source code is as follows:

              

        Analysis: The application contains a div and a button. The div section is used to display information from the server. When the button is clicked, it is responsible for calling a function called loadXMLDoc().

Fourth, create the  XMLHttpRequest object

       XMLHttpRequest is the basis of AJAX and is used to exchange data with the server behind the scenes. This means that parts of a page can be updated without reloading the entire page.

       The syntax for creating an XMLHttpRequest object is:

                     variable=new XMLHttpRequest();

       Older versions of Internet Explorer (IE5 and IE6) used ActiveX objects:

                     variable=new ActiveXObject("Microsoft.XMLHTTP");

       For all modern browsers, including IE5 and IE6, please check if the browser supports the XMLHttpRequest object. If supported, an XMLHttpRequest object is created. If not supported, create ActiveXObject.

5. Send a request to the server

        The XMLHttpRequest object is used to exchange data with the server. To send the request to the server, we use the open() and send() methods of the XMLHttpRequest object:

                          xmlhttp.open("GET","ajax_info.txt",true);
                          xmlhttp.send();

       

6. Server response

       To get a response from the server, use the responseText or responseXML properties of the XMLHttpRequest object.

       

 

       If the response from the server is not XML, use the responseText property, which returns the response as a string.

       If the response from the server is XML and needs to be parsed as an XML object, use the responseXML attribute.

7. Summary

       Through the above basic introduction to Ajax and finding relevant information, it is not difficult to find that the biggest advantage of Ajax is that the page is not refreshed, and it communicates with the server within the page, which gives the user a very good experience. In addition, it communicates with the server in an asynchronous manner and has a faster response capability; its principle of "fetching data on demand" can also minimize the burden on the server caused by redundant requests and responses. The above are the significant advantages of Ajax, but the defects it brings cannot be ignored. The abandonment of the back button by Ajax makes it impossible to cooperate well with js, which is a relatively serious problem. ; In addition, in the information age where network security problems are increasingly prominent, new technologies have also brought new security threats to IT companies. Ajax technology is like establishing a direct channel for enterprise data, which makes ajax unavoidable. There are some security weaknesses, such as cross-site footstep attacks, SQL injection attacks, etc. Therefore, the development opportunities and challenges of Ajax coexist.

       References and articles: http://www.runoob.com/ajax/ajax-intro.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324695806&siteId=291194637