aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/xmlhttprequesteventtarget/onprogress/index.html
blob: ad2bced50b8105bce1459064568e83eff3289aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
title: XMLHttpRequestEventTarget.onprogress
slug: Web/API/XMLHttpRequestEventTarget/onprogress
translation_of: Web/API/XMLHttpRequestEventTarget/onprogress
---
<p>{{APIRef("XMLHttpRequest")}}</p>

<p><strong><code>XMLHttpRequestEventTarget.onprogress</code></strong> 是在 {{domxref("XMLHttpRequest")}} 完成之前周期性调用的函数。</p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre><em>XMLHttpRequest</em>.onprogress = <em>callback</em>;</pre>

<h3 id="值"></h3>

<ul>
 <li><code><em>callback</em></code> 在请求完成之前周期性调用的函数。</li>
</ul>

<h3 id="Example" name="Example">事件</h3>

<ul>
 <li><em><code>event.loaded</code></em>  已传输的数据量</li>
 <li><em><code>event.total</code></em>  总共的数据量</li>
</ul>

<pre>XMLHttpRequest.onprogress = function (event) {
  event.loaded;
  event.total;
};</pre>

<h2 id="Example" name="Example">示例</h2>

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

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

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('XMLHttpRequest', '#handler-xhr-onload')}}</td>
   <td>{{Spec2('XMLHttpRequest')}}</td>
   <td>WHATWG living standard</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div class="hidden">此兼容性表格是自动生成的。如果您想向此表格贡献数据,请前往 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 向我们发送合并请求。</div>

<p>{{Compat("api.XMLHttpRequestEventTarget.onprogress")}}</p>