forked from WTFAcademy/WTF-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.js
More file actions
31 lines (25 loc) · 862 Bytes
/
Copy pathNetwork.js
File metadata and controls
31 lines (25 loc) · 862 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
const axios = require('axios');
// 创建 XMLHttpRequest 对象
let xhr = new XMLHttpRequest();
// 指定请求的方法和 URL
xhr.open("GET", 'https://api.github.com/search/users?q=amazingang', true);
// 设置回调函数,处理请求的响应
xhr.onreadystatechange = function () {
// 请求成功
if (xhr.readyState == 4 && xhr.status == 200)
// 处理响应数据
console.log(JSON.parse(xhr.responseText));
}
// 发送请求
xhr.send();
fetch('https://api.github.com/search/users?q=amazingang')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
axios.get('https://api.github.com/search/users?q=amazingang')
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});