最基本要有兩個東西
- XMLHttpRequest.open() 初始化整個
XMLHttpRequest,設定 request 類型(GET 甚麼的)、URL、還有要不要非同步(到底甚麼 Case 會不用...) - XMLHttpRequest.send() 這個一定一定要放在最後,設定好在 send
tree pay
通常會加上這些
XMLHttpRequest.onload = callbackXMLHttpRequest.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


![[Note] 網路是如何運作的](https://static.coderbridge.com/images/covers/default-post-cover-3.jpg)