ajax.js 427 B

12345678910111213141516
  1. function ajax(method, url,foo) {
  2. let xhr = new XMLHttpRequest();
  3. xhr.open(method, url);
  4. xhr.send();
  5. xhr.onreadystatechange = function () {
  6. if (xhr.readyState === 4) {
  7. if (xhr.status === 200) {
  8. // console.log(xhr.responseText);
  9. let data = JSON.parse(xhr.responseText);
  10. foo(data);
  11. // return data;
  12. }
  13. }
  14. }
  15. }