What is the role of Ajax? A detailed explanation of the role and wording of Ajax

Source: Internet
Author: User
This article is mainly about the definition of Ajax, as well as the role of Ajax, and finally on the elaboration of Ajax, let's look at this article together

What is AjAx?

Asynchronous JavaScript and XML.

What is the role?

Using AJAX to Exchange data with the server, Ajax can use Web pages to implement layout updates.

This means that you can update a part of a webpage without reloading the entire page.

How to implement Ajax?

The XMLHttpRequest object, which can be used to asynchronously send a request to the server, get a response update, and complete a partial update. Open Send Responsetext/responsexml local response. (Want to see more on the Topic.alibabacloud.comAJAX Development Manual section of the study)

Usage Scenarios

Logon failure does not jump to page.

Registration real-time prompts for the presence of the user name.

The linkage between provincial and urban areas.

Manage image servers for time-lapse loading.

Native AjAx notation:

var xhr=null, if (window. XMLHttpRequest) {//non ie kernel XHR = new XMLHttpRequest ();} else if (window. ActiveXObject) {//IE kernel, where earlier versions of IE are written differently, you can query under XHR = new ActiveXObject ("Microsoft.XMLHTTP");} else {XHR = Nu ll      } if (XHR) {Xhr.open ("GET", "ajaxserver.action"); Xhr.onreadystatechange = function () {//ReadyState value Description//0, initialization, XHR object has been created, open//1 not executed, loaded, OP has been called En method, but not yet sent request//2, loading complete, request has been sent complete//3, interactive, can receive partial data//Status Value description//200: Success//404: No files, queries, or URLs//500: The server generates an internal error if (xhr.readystate = = 4 && xhr.status = = 200) {//Here you can             Processing of the returned content//generally returns JSON or XML data format console.log (xhr.responsetext);         Active release, JS itself will also be recycled XHR = null;     }     }; Xhr.send (); }

Jquery AjAx notation:

$.ajax ({         URL: "servlet",         type: "Post",//get         data:{},         async:true,         cache:true, complete         : function () {},         Traditional:false,         dataType: "JSON",         success:function (data) {},         error:function ( ){}      });   $.post ("Servlet", {},function (data) {}, "JSON");  $.get ("Servlet", function (data) {}, "JSON");

This is the end of this article (want to see more on the Topic.alibabacloud.comAJAX User manual section of the study), there are questions can be in the message below the question.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.