Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function loadPhones() {
  2.  
  3.       var xhr = new XMLHttpRequest();
  4.  
  5.       xhr.open('POST', 'some.php', true);
  6.  
  7.       xhr.send();
  8.  
  9.       xhr.onreadystatechange = function() {
  10.  
  11.         console.log(xhr);
  12.        
  13.         if (xhr.readyState != 4) return;
  14.  
  15.         button.innerHTML = 'Готово!';
  16.  
  17.         console.log(xhr);
  18.  
  19.         if (xhr.status != 200) {
  20.           // обработать ошибку
  21.           alert(xhr.status + ': ' + xhr.statusText);
  22.         } else {
  23.           // вывести результат
  24.           console.log(xhr.responseText);
  25.         }
  26.  
  27.       }
  28.  
  29.       button.innerHTML = 'Загружаю...';
  30.       button.disabled = true;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement