JSFiddle - React, Tailwind, and code Playground
by pvtd264
HTML
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
JavaScript
// 1. Sử dụng axios để tải nội dung dưới dạng json từ đường link sau về và hiển ra trình duyệt sử dụng document.write
// Link: https://randomuser.me/api/
// Có thể tìm link tới thư viện axios tại: https://cdnjs.com/
// Để thêm thư viện vào jsfiddle, nhấn vào Resources ở cột trái, nhập link vào rồi ấn (+)
// 2. Làm tương tự, thay vì dùng axios, hãy dùng fetch (google để biết cách dùng)
var url = "https://randomuser.me/api/";
/*
axios.get(url)
.then(function (response) {
document.write(JSON.stringify(response.data));
});
*/
fetch(url)
.then(
function(response) {
if (response.status !== 200) {
console.log('Lỗi, mã lỗi ' + response.status);
return;
}
response.json().then(data => {
document.write(JSON.stringify(data));
console.log(data);
})
}
)
.catch(err => {
console.log('Error :-S', err)
});