function $ajax({type = "get", url, data, success, error}){ var xhr = null; try{ xhr = new xmlhttprequest(); }catch(error){ xhr = new activexobject("microsoft.xmlhttp"); } if(type == "get" && data){ url += "?" + querystring(data); } xhr.open(type, url, true); if(type == "get"){ xhr.send(); }else{ //一定要放在send方法之前 xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded'); xhr.send(querystring(data)); } //等待响应 xhr.onreadystatechange = function(){ if(xhr.readystate == 4){ if(xhr.status == 200){ //当数据下载完成以后如何处理数据的操作是不一定,回调函数 if(success){ success(xhr.responsetext); } }else{ if(error){ error("error:" + xhr.status); } } } } } function ajax(){ //url 是地址 a1是参数 就可以了 var url = 'http://xinfengxiang/index/investor/notice'; var page = 1; var pagesize = 20; $ajax(url,{page:page,pagesize:pagesize},function(res){ //这里用jq 转jq数组 处理拼接数据就好了 alert(res) }) } ajax()