# 將 axios.get 套件功能,包覆 XMLHttpRequest 再用 promise 格式撰寫 const url = 'https://raw.githubusercontent.com/hexschool/2021-ui-frontend-job/master/frontend_data.json'; const axios = { get:url=>{ return new Promise((resolved,reject)=>{ const que = new XMLHttpRequest(); console.log(que); que.open('GET',url); que.onload = ()=>resolved(que.responseText); que.onerror = ()=>reject(que.statusText); que.send() }) } } axios.get(url).then(data=>console.log(data)) .catch(err=>console.log(err))
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up