XMLHttpRequestEventTarget.onprogress

XMLHttpRequestEventTarget.onprogress 是在 XMLHttpRequest 完成之前周期性调用的函数。

语法

XMLHttpRequest.onprogress = callback;

  • callback 在请求完成之前周期性调用的函数。

事件

  • event.loaded  已传输的数据量
  • event.total  总共的数据量
XMLHttpRequest.onprogress = function (event) {
  event.loaded;
  event.total;
};

示例

var xmlhttp = new XMLHttpRequest(),
  method = 'GET',
  url = 'https://developer.mozilla.org/';

xmlhttp.open(method, url, true);
xmlhttp.onprogress = function () {
  //do something 
};
xmlhttp.send();

规范

Specification Status Comment
XMLHttpRequest Living Standard WHATWG living standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onprogressChrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown