-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax.js
More file actions
31 lines (26 loc) · 831 Bytes
/
ajax.js
File metadata and controls
31 lines (26 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function getDataByAjax(){
var xhr = new XMLHttpRequest();
xhr.open("GET","https://reqres.in/api/users?delay=3",true);
xhr.send();
xhr.onreadystatechange = function(){
console.log(this.readyState);
if(this.readyState== 1){
console.log("Server connection established");
}
if(this.readyState== 2){
console.log("request received");
}
if(this.readyState== 3){
console.log("processing request");
}
if(this.readyState== 4 && this.status==200){
var data = JSON.parse(this.response);
console.log(data);
}
}
// xhr.onload= function(){
// var data = JSON.parse(this.response);
// console.log(data);
// }
}
getDataByAjax();