blob: d98eabf064373fe3465109abf254a5fecfa58323 (
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
|
---
title: XMLHttpRequest.abort()
slug: Web/API/XMLHttpRequest/abort
tags:
- XMLHttpRequest
translation_of: Web/API/XMLHttpRequest/abort
---
<p>{{APIRef('XMLHttpRequest')}}</p>
<p>如果该请求已被发出,<strong>XMLHttpRequest.abort()</strong> 方法<span style="cursor: pointer;">将终止该</span>请求。当一个请求被<span style="cursor: pointer;">终止</span>,它的 {{domxref("XMLHttpRequest.readyState", "readyState")}} 将被置为 {{domxref("XMLHttpRequest.UNSENT")}} (0),并且请求的 {{domxref("XMLHttpRequest.status", "status")}} 置为 0。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox notranslate">xhrInstance.abort();</pre>
<h3 id="参数">参数</h3>
<p>无。</p>
<h3 id="返回值">返回值</h3>
<p><code>undefined</code></p>
<h2 id="示例">示例</h2>
<pre class="brush: js notranslate">var xhr = new XMLHttpRequest(),
method = "GET",
url = "https://developer.mozilla.org/";
xhr.open(method, url, true);
xhr.send();
if (OH_NOES_WE_NEED_TO_CANCEL_RIGHT_NOW_OR_ELSE) {
xhr.abort();
}</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('XMLHttpRequest', '#the-abort()-method')}}</td>
<td>{{Spec2('XMLHttpRequest')}}</td>
<td>WHATWG living standard</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>{{Compat("api.XMLHttpRequest.abort")}}</div>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/zh-CN/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest">使用 XMLHttpRequest</a></li>
</ul>
|