Ajax features and garbled issues, Ajax features garbled issues
The full name of ajax is asynchronous javascript and XML, Which is asynchronous js and XML. It is a local refresh and asynchronous operation.
We all know that ajax is single-threaded and synchronous, but why can a single thread be asynchronous is certainly unknown to most people? The following is a brief explanation by Zhang YANNI (not very official, but it is easy to understand ):
Before explaining this, I would like to introduce the linear data structure. We can regard the single linear data structure as a line segment. You can see that the line segment is always with its head and end, A single thread is the header of a line segment with no front zone and no back zone at the end. Each element in the middle has two front and back elements. When one element is missing, two elements will be known and told to you at the same time. In addition, none of the elements can be used.
The callback function passes function A to function B as A parameter and function B executes function. The most common usage of callback functions is the succes () and error () functions used when ajax requests data, the first parameter in setInterval, and the callback function. The literal meaning of a callback function, a callback function, or a callback function is not to take the road back. Therefore, when the callback function success () or error is triggered, ajax overhead and goes again. Then it is asynchronous, while ajax is asynchronous, similar to him, there is also es6 promise (asynchronous synchronous operation ).
The browser process is multi-process. Why is it just like you calling XXX ~
The second problem is that when the omnipotent front-end encounters ajax to obtain background data, what is garbled code.
-The network speed may be slow.
-Maybe the encoding format is not uniform, and your backend brother has pitted you, Hahahaha
Can I remember all the native ajax code? I 'd like to show you the code again:
// 1. create the xmlhttpRequest object var xhr; try {xhr = new XMLHttpRequest (); console. log (5555)} catch (e) {// earlier version of IE browser compatible with xhr = new ActiveXobject ("Microsoft. XMLHTTP ");} finally {console. log (1111)} // try {} catch {} finally {} Here is the method to handle exceptions, and if {} else {} is also OK // if (window. XMLHttpRequest) {// xhr = new XMLHttpRequest (); //} else {// compatibility with earlier ie browsers // xhr = new ActiveXobject ("Microsoft. XMLHTTP ") //} // 2. establish an asynchronous connection to xhr. open ("get", "url/+ string", true/false); // true is asynchronous, and false is synchronous // xhr. open ("post", "url", true/false) // 3. send asynchronous request xhr. send (null); // get xhr. send (string); // post // 4. obtain the returned data xhr. onreadystatechange = function () {if (xhr. readystate) = 4 & (xhr. status = 200) {var data = xhr. responseText; var data = JSON. parse (data); show (data) ;}} function show (data) {document. getElementById ("div1 "). innerHTML = data ;}
The above section describes the Ajax features and Garbled text. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!