[極短篇] 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

MTR04_0715

MTR04_0715

【Day01】用tkinter製作圖形視窗介面(GUI)

【Day01】用tkinter製作圖形視窗介面(GUI)

SingleLiveEvent

SingleLiveEvent


Comments