aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/abortsignal/onabort/index.html
blob: e72dd94c4aa0d9822bf856eb096b78a4d7435cd4 (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
---
title: AbortSignal.onabort
slug: Web/API/AbortSignal/onabort
tags:
  - API
  - Fetch
  - onabort
  - 事件处理
  - 属性
  - 测试
  - 终止属性
translation_of: Web/API/AbortSignal/onabort
---
<div>{{APIRef("DOM")}}{{SeeCompatTable}}</div>

<div>当事件被{{event("abort_(cancellable_fetch)", "终止")}}{{domxref("FetchSignal")}}接口的<strong><code>onabort</code></strong> 只读属性就会被调用。例子.当fetch的请求信号被终止。</div>

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

<pre class="brush: js">abortSignal.onabort = function() { ... };</pre>

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

<p>在下面例子中, 我们将创建一个新的 <code>AbortController</code> 对象,并获取它的{{domxref("AbortSignal")}} (在 <code>signal</code> 属性中可用)。然后我们查看 <code>onabort</code> 属性是否被终止,并将相应的日志输出到控制台。</p>

<pre class="brush: js">var controller = new AbortController();
var signal = controller.signal;

signal.onabort = function() {
  console.log('Request aborted');
};
</pre>

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

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规格</th>
   <th scope="col">状态</th>
   <th scope="col">标注</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-abortsignal-aborted', 'onabort')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>初始定义</td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("api.AbortSignal.onabort")}}</p>

<h2 id="参考文档">参考文档</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Fetch_API">Fetch API</a></li>
</ul>