ajax.js 492 B

12345678910111213141516
  1. function ajaxFun(url,foo) {
  2. // 第一步 创建XMLHttpRequest 对象;
  3. var xmlh = new XMLHttpRequest();
  4. // 第二步 发送请求
  5. xmlh.open("GET", url, true);
  6. xmlh.send();
  7. // 第三步 处理请求结果
  8. xmlh.onreadystatechange = function () {
  9. if (xmlh.readyState == 4 && xmlh.status == 200) {
  10. var resObj = JSON.parse(xmlh.responseText)
  11. // console.log(resObj)
  12. // return resObj;
  13. foo(resObj)
  14. }
  15. }
  16. }