This is the sixth day of my participation in the August More Text Challenge. For details, see “August More Text Challenge”.

1. Ajax

Ajax is short for “Asynchronous JavaScript and XML.” He refers to a web development technique for creating interactive web applications.

The principle of Ajax is to use the XmlHTTPRequest object to make asynchronous requests to the server to get data from the server, Javascript is then used to manipulate the DOM to update the page. The most critical step in this is getting the request data from the server.

XMLHTTPRequest is the core mechanism of Ajax, it was first introduced in IE5, is a technology to support asynchronous requests. Simply put, this means that javascript can make requests to the server and process responses in a timely manner without blocking the user and achieving the effect of no refresh.

// First, create the XMLHttpRequest object
var xhr = new XMLHttpRequest();
function ajax() {
    // Second, register the callback function
    xhr.onreadystatechange =callback1;
    {
       if (xhr.readyState == 4)
          if (xhr.status == 200) {
                varresponseText = xhr.responseText; }}// The third step is to configure the request information, open(),get
    // Get request parameters added after url,.ashx? methodName = GetAllComment&str1=str1&str2=str2
    xhr.open("post"."/ashx/myzhuye/Detail.ashx? methodName=GetAllComment".true);
    // Request headers need to be configured for post requests
    //xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // The fourth step is to send the request. In the post request, the parameters to be passed are put here
    xhr.send("methodName = GetAllComment&str1=str1&str2=str2");/ /"
}
// Step 5: create the callback function
function callback1() {
    if (xhr.readyState == 4)
        if (xhr.status == 200) {
            // Retrieve the returned data
            var data = xhr.responseText;     
        }
Copy the code

2. The advantages of Ajax

  1. The biggest point is that the page does not refresh, the user experience is very good.

  2. Using asynchronous mode to communicate with the server, with faster response ability.

  3. Some of the previous server burden can be transferred to the client, using the idle capacity of the client to deal with, reduce the burden of the server and bandwidth, save space and broadband rental costs. And reduce the burden of the server, Ajax is the original “on-demand data”, can minimize the redundant request, and response to the burden of the server.

  4. Based on standardized and widely supported technologies, there is no need to download plug-ins or applets.

3. Disadvantages of Ajax

  1. Ajax does not support the browser back button.
  2. Security Issues Ajax exposes the details of interacting with the server.
  3. Support for search engines is weak.
  4. Breaks the exception mechanism of the program.
  5. Not easy to debug.