Home > Web Front-end > JS Tutorial > body text

Introduction to ajax and tutorial on writing native ajax in JS

PHP中文网
Release: 2017-06-21 11:08:58
Original
1206 people have browsed it

ajax

1. What is ajax
The full name of ajax is Asynchronous JavaScript and XML. Among them, Asynchronous means asynchronous, which refers to asynchronous JavaScript and XML.
 AJAX is a technology used to create fast dynamic web pages. AJAX enables web pages to update asynchronously by exchanging small amounts of data with the server in the background. This means that parts of the page can be updated without reloading the entire page.
If traditional web pages (not using AJAX) need to update content, the entire web page must be reloaded.
2. Technologies included in ajax
Everyone knows that ajax is not a new technology, but a combination of several original technologies. It is composed of the following technologies.
  1. Use CSS and XHTML to express.
 2. Use DOM model for interaction and dynamic display.
  3. Use XMLHttpRequest to communicate asynchronously with the server.
  4. Use javascript to bind and call.
4.ajax principle
The principle of Ajax is simply to send an asynchronous request to the server through the XmlHttpRequest object, obtain the data from the server, and then use javascript to operate the DOM and update the page.
5. Implementation of ajax request
1. Create XmlHttpRequest object
if (window.XMLHttpRequest) {
   // IE7+, Firefox, Chrome, Opera, Safari browser execution code
  xmlhttp= new XMLHttpRequest();
  } else {
     // IE6, IE5 browser execution code
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 2. Connect to the server
  xmlhttp.open("GET","http://127.0.0.1:8080",true);
 3.Send request

  xmlhttp.send();
 4.Wait The server returns the content and processes it. xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && =xmlhttp.responseText;
   }
  }

The above is the detailed content of Introduction to ajax and tutorial on writing native ajax in JS. 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