XMLHttpRequestLevel 2的一些新特性:
- 设置过期时间
- 使用FormData更好的数据托管
- 传送二进制流
- 添加了发送进度改变事件,可以侦听发送了多少字节。
- 允许安全跨域,类似于加载其他域的script.
- 可复写加载内容的MIME type和编码
XHR的事件例表:
attribute | type | Explanation |
---|---|---|
onloadstart | loadstart | When the request starts. |
onprogress | progress | While loading and sending data. |
onabort | abort | When the request has been aborted, either by invoking theabort() method or navigating away from the page. |
onerror | error | When the request has failed. |
onload | load | When the request has successfully completed. |
ontimeout | timeout | When the author specified timeout has passed before the requestcould complete. |
onloadend | loadend | When the request has completed, regardless of whether or not itwas successful. |