[極短篇] XMLHttpRequest


Posted by Lauviah0622 on 2020-08-03

最基本要有兩個東西

  • XMLHttpRequest.open() 初始化整個 XMLHttpRequest ,設定 request 類型(GET 甚麼的)、URL、還有要不要非同步(到底甚麼 Case 會不用...)
  • XMLHttpRequest.send() 這個一定一定要放在最後,設定好在 send tree pay

通常會加上這些

  • XMLHttpRequest.onload = callback
  • XMLHttpRequest.onerror = callback
    上面這兩個相當於
    XMLHttpRequest.addEventListener('load', callback)
    XMLHttpRequest.addEventListener('error', callback)
    

可以用

  • XMLHttpRequest.response 拿 Request 的 body,可能有各種形式
  • XMLHttpRequest.status 拿 HTTP status

那要怎麼拿 Header 阿... => XMLHttpRequest.getResponseHeader()
XMLHttpRequest.setRequestHeader() 要記得放在 send() 之前。

Big guy is John,感謝收看。

參考:MDN


#XMLHttpReqeust







Related Posts

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x

解題 - 找出所有等腰三角形

解題 - 找出所有等腰三角形

【隨堂筆記】資料結構基礎概論

【隨堂筆記】資料結構基礎概論


Comments