Ajax (Ajax)Pros: Implement partial Refresh (Async-page continuation, no wait, no refresh) Disadvantage: cross-domain (violating the same origin policy) [proxy Proxy, jsonp,cors] homology policy: Address to access: Protocol name same, domain name same, port same
synchronous vs. asynchronousSync: Call (wait, block) var w=show (); Console.log (w);//123 async: Send Message (non-blocking) Show (function (w) {Console.log (w);//123}) ... The following code continues to execute ....... .....
Add
Json.parse (); Convert string to Object
ajsx.js Code/***ajax Request * @param {string} URL request Address * @param {string} method request Method (Get/post) * @param {Object} data request data (POST) * @param { Function} Success Successful callback function * @param {function} fail callback function */
function Ajax (Url,method,data,success,fail) { //1. Generating asynchronous Objects var xhr; if (window. XMLHttpRequest) { xhr=new XMLHttpRequest ();//Mainstream browser }else{ xhr=new acitivexobject (' Microsoft.XMLHTTP '); /Old IE    }    //2. Create a connection (open channel) xhr.open (Method,url , true); //3. Send xhr.send (data); //4. Listen for events, Get Results xhr.onreadystatechange=function () { ReadyState: Send status, 4 means send complete if (this.readystate===4) { //status: Results returned, 200 indicates success if (this.status==200) { //Call Success callback function success (This.responsetext);//responseText: Results }else{ //Call fail callback function fail (this.status);//Pass the failed status code in } } }}
10.19 Essays