Introduction and use of Ajax

First, what is Ajax

Ajax stands for Asynchronous JavaScript and XML (Asynchronous JavaScript and XML), is a without having to reload the entire page, technical part of the page can be updated

 

Two, Ajax's strengths and weaknesses

1, the advantages:

  • By asynchronous mode to enhance the user experience
  • Optimize the transmission between the browser and the server, reduce unnecessary data back and forth, reducing bandwidth consumption
  • Ajax engine running on the client, would have to bear a part of the work undertaken by the server, reducing the server load large amount of users

 

2, shortcomings

  • Does not support the browser back button
  • Security issues, Ajax exposed the details of the interaction with the server
  • Support for the search engines is relatively weak

 

Three, Ajax uses - implementation steps

1, create XMLHttpRequest object, the object is to create an asynchronous call

var XHR;
if(window.XMLHttpRequest){
  XHR=new XMLHttpRequest();                   //IE7+, Firefox, Chrome, Opera, Safari...
}else{
  XHR=new ActiveXObject("Microsoft.XMLHTTP"); //IE6,IE5

2, create a new HTTP request and the HTTP request method is specified, URL and authentication information

Xhr.open (Method, URL, the async);
 // Method: type of request, GET, or alternatively POST --------- 
// URL: location of the file on the server -------- ------ necessary parameters 
// the async: to true (asynchronous) or false (synchronous) ---- optional 
// above parameters are using to add ""

3, is provided in response to the state change function of the HTTP request

4, sends an HTTP request

request.send();

5, to obtain data returned from an asynchronous call

6, using JavaScript and DOM implementations partial refresh

 

Guess you like

Origin www.cnblogs.com/Leophen/p/11208931.html