Ajax基础原理与应用
Ajax函数封装ajax.js // Get / Post // 参数 get post // 是否异步 // 如何处理响应数据 // URL // var handleResponse = function(response) { // // } // ajax.get('demo1.php', 'name=zhangsan&age=20', handleResponse, true) // ajax.post('demo1.php', 'name=zhangsan&age=20', handleResponse, true) function Ajax() { // 初始化方法 this.init = function() { this.xhr = new XMLHttpRequest(); }; // get请求方法 this.get = function(url, parameters, callback, async = true) { this.init(); if (async) { // 异步请求 this.xhr.onreadystatechange = function() { // this => this.xhr if (this.readyState == 4 && this.status == 200) { callback(this