Examples of native AJAX writing and ajax instance analysis
This article analyzes the native AJAX writing method. Share it with you for your reference. The specific analysis is as follows:
Although many JS frameworks now provide AJAX call methods, we can directly call them without having to know the specific implementation principles, however, I think it is difficult to do the best without learning about one thing at the basic level.
Var XHR = null; if (window. XMLHttpRequest) {// non-IE kernel XHR = new XMLHttpRequest ();} else if (window. activeXObject) {// IE kernel. The earlier IE versions are written differently. For details, see XHR = new ActiveXObject ("Microsoft. XMLHTTP ") ;}else {XHR = null;} if (XHR) {XHR. open ("GET", "ajaxServer. action "); XHR. onreadystatechange = function () {// readyState value description // 0, initialization, XHR object created, open // 1 not executed, load, open method called, but no request has been sent // 2, the load is complete, the request has been sent // 3, interaction, some data can be received // status description // 200: success // 404: No file, query, or URl found // 500: the server generates an internal error if (XHR. readyState = 4 & XHR. status = 200) {// The returned content can be processed here // The console is generally returned in JSON or XML data format. log (XHR. responseText); // actively released. JS will also recycle XHR = null ;}}; XHR. send ();}
I hope this article will help you with Ajax programming.