ajax.js 402 B

1234567891011121314
  1. const p = new Promise((resolve,reject)=>{
  2. const xhr = new XMLHttpRequest()
  3. xhr.open("GET","https://api.apiopen.top/getJoke")
  4. xhr.send()
  5. xhr.onreadystatechange = function(){
  6. if(xhr.readyState === 4){
  7. if(xhr.status >= 200 && xhr.status < 300){
  8. resolve(xhr.response)
  9. }else{
  10. reject(xhr.status)
  11. }
  12. }
  13. }
  14. })