-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi_call.js
More file actions
19 lines (17 loc) · 565 Bytes
/
api_call.js
File metadata and controls
19 lines (17 loc) · 565 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var url="https://api.github.com/users";
var xhr= new XMLHttpRequest();
xhr.open('GET',url);
xhr.onreadystatechange=()=>
{
if(xhr.readyState==4 && xhr.status==200)
{
var m=JSON.parse(xhr.responseText);
console.log(typeof(xhr.responseText));
console.log(typeof(m));
console.log(m);
// document.querySelector('div').innerHTML=xhr.responseText;
document.querySelector('img').setAttribute('src',m[0].avatar_url);
document.querySelector('div').innerHTML=`<h3>${m[0].login}</h3>`;
}
}
xhr.send();