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.