diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/xmlhttprequesteventtarget | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/xmlhttprequesteventtarget')
6 files changed, 352 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/index.html new file mode 100644 index 0000000000..dc6ddc6d37 --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/index.html @@ -0,0 +1,64 @@ +--- +title: XMLHttpRequestEventTarget +slug: Web/API/XMLHttpRequestEventTarget +tags: + - AJAX + - API + - XMLHttpRequest + - 参考 +translation_of: Web/API/XMLHttpRequestEventTarget +--- +<p>{{APIRef("XMLHttpRequest")}}</p> + +<p><code>XMLHttpRequestEventTarget</code> 是一个描述事件处理程序的接口,你可以在一个用于处理 {{ domxref("XMLHttpRequest") }} 事件的对象中使用到该事件处理程序。</p> + +<p>{{InheritanceDiagram}}</p> + +<h2 id="属性">属性</h2> + +<dl> + <dt>{{ domxref("XMLHttpRequestEventTarget.onabort") }}</dt> + <dd>当请求失败时调用该方法,接受 {{event('abort')}} 对象作为参数。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.onerror") }}</dt> + <dd>当请求发生错误时调用该方法,接受 {{event('error')}} 对象作为参数。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.onload") }}</dt> + <dd>当一个 HTTP 请求正确加载出内容后返回时调用,接受 {{event('load')}} 对象作为参数。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.onloadstart") }}</dt> + <dd>当一个 HTTP 请求开始加载数据时调用,接受 {{event('loadstart')}} 对象作为参数。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.onprogress") }}</dt> + <dd>间歇调用该方法用来获取请求过程中的信息,接受 {{event('progress')}} 对象作为参数。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.ontimeout") }}</dt> + <dd>当超时时调用,接受 {{event("timeout")}} 对象作为参数;只有设置了 <code>XMLHttpRequest</code> 对象的 <code>timeout</code> 属性时,才可能发生超时事件。</dd> + <dt>{{ domxref("XMLHttpRequestEventTarget.onloadend") }}</dt> + <dd>当内容加载完成,不管失败与否,都会调用该方法,接受 {{event('loadend')}} 对象作为参数。</dd> +</dl> + +<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')}}</td> + <td>{{Spec2('XMLHttpRequest')}}</td> + <td>WHATWG living standard</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.XMLHttpRequestEventTarget")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{ domxref("XMLHttpRequest") }}</li> + <li><a href="/zh-CN/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest">使用 XMLHttpRequest</a></li> +</ul> diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/onabort/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/onabort/index.html new file mode 100644 index 0000000000..38d305c1c2 --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/onabort/index.html @@ -0,0 +1,56 @@ +--- +title: XMLHttpRequestEventTarget.onabort +slug: Web/API/XMLHttpRequestEventTarget/onabort +translation_of: Web/API/XMLHttpRequestEventTarget/onabort +--- +<div>{{APIRef("XMLHttpRequest")}}</div> + +<p><strong><code>XMLHttpRequestEventTarget.onabort</code></strong> 会在 {{domxref("XMLHttpRequest")}} 交易操作被诸如 {{domxref("XMLHttpRequest.abort()")}} 函数中止时调用。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>XMLHttpRequest</em>.onabort = <em>callback</em>;</pre> + +<h3 id="值">值</h3> + +<ul> + <li><code><em>callback</em></code> 在交易被中止时调用的函数。</li> +</ul> + +<h2 id="Example" name="Example">示例</h2> + +<pre class="brush: js">var xmlhttp = new XMLHttpRequest(), + method = 'GET', + url = 'https://developer.mozilla.org/'; + +xmlhttp.open(<em>method</em>, <em>url</em>, true); +xmlhttp.onabort = function () { + console.log('** 请求被中止'); +}; +xmlhttp.send(); +//.. +xmlhttp.abort(); // 这将会调用我们上面定义的 onabort 回调函数 +</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', '#handler-xhr-onabort')}}</td> + <td>{{Spec2('XMLHttpRequest')}}</td> + <td>WHATWG living standard</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.XMLHttpRequestEventTarget.onabort")}}</p> diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/onerror/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/onerror/index.html new file mode 100644 index 0000000000..c6931f08ef --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/onerror/index.html @@ -0,0 +1,58 @@ +--- +title: XMLHttpRequestEventTarget.onerror +slug: Web/API/XMLHttpRequestEventTarget/onerror +tags: + - API + - Event Handler + - XMLHttpRequestEventTarget +translation_of: Web/API/XMLHttpRequestEventTarget/onerror +--- +<div>{{APIRef("XMLHttpRequest")}}</div> + +<p><strong><code>XMLHttpRequestEventTarget.onerror</code></strong> 是{{domxref("XMLHttpRequest")}} 事务由于错误而失败时调用的函数。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>XMLHttpRequest</em>.onerror = <em>callback</em>;</pre> + +<h3 id="Values">Values</h3> + +<ul> + <li><code><em>callback</em></code> 是当请求失败时执行的函数。</li> +</ul> + +<h2 id="Example" name="Example">举例</h2> + +<pre class="brush: js">var xmlhttp = new XMLHttpRequest(), + method = 'GET', + url = 'https://developer.mozilla.org/'; + +xmlhttp.open(<em>method</em>, <em>url</em>, true); +xmlhttp.onerror = function () { + console.log("** An error occurred during the transaction"); +}; +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-onerror')}}</td> + <td>{{Spec2('XMLHttpRequest')}}</td> + <td>WHATWG living standard</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.XMLHttpRequestEventTarget.onerror")}}</p> diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/onload/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/onload/index.html new file mode 100644 index 0000000000..8e2c27016f --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/onload/index.html @@ -0,0 +1,54 @@ +--- +title: XMLHttpRequestEventTarget.onload +slug: Web/API/XMLHttpRequestEventTarget/onload +translation_of: Web/API/XMLHttpRequestEventTarget/onload +--- +<div>{{APIRef("XMLHttpRequest")}}</div> + +<p><strong><code>XMLHttpRequestEventTarget.onload</code></strong> 是 {{domxref("XMLHttpRequest")}} 请求成功完成时调用的函数。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>XMLHttpRequest</em>.onload = <em>callback</em>;</pre> + +<h3 id="值">值</h3> + +<ul> + <li><code><em>callback</em></code> 是请求成功完成时要执行的函数。它接收一个 {{domxref("ProgressEvent")}} 对象作为它的第一个参数。<em>this</em> 的值(即上下文)与此回调的 {{domxref("XMLHttpRequest")}} 相同。</li> +</ul> + +<h2 id="Example" name="Example">示例</h2> + +<pre class="brush: js">var xmlhttp = new XMLHttpRequest(), + method = 'GET', + url = 'https://developer.mozilla.org/'; + +xmlhttp.open(<em>method</em>, <em>url</em>, true); +xmlhttp.onload = function () { + // 处理取回的数据(在 xmlhttp.response 中找到) +}; +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> + + + +<p>{{Compat("api.XMLHttpRequestEventTarget.onload")}}</p> diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/onloadstart/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/onloadstart/index.html new file mode 100644 index 0000000000..1501afd132 --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/onloadstart/index.html @@ -0,0 +1,54 @@ +--- +title: XMLHttpRequestEventTarget.onloadstart +slug: Web/API/XMLHttpRequestEventTarget/onloadstart +translation_of: Web/API/XMLHttpRequestEventTarget/onloadstart +--- +<div>{{APIRef("XMLHttpRequest")}}</div> + +<p><strong><code>XMLHttpRequestEventTarget.onloadstart</code></strong> 在{{domxref("XMLHttpRequest")}} 开始传送数据时被调用</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>XMLHttpRequest</em>.onloadstart = <em>callback</em>;</pre> + +<h3 id="值">值</h3> + +<ul> + <li><code><em>callback</em></code> 是开始传送数据时被调用的回调函数</li> +</ul> + +<h2 id="Example" name="Example">示例</h2> + +<pre class="brush: js">var xmlhttp = new XMLHttpRequest(), + method = 'GET', + url = 'https://developer.mozilla.org/'; + +xmlhttp.open(<em>method</em>, <em>url</em>, true); +xmlhttp.onloadstart = function () { + console.log("Download underway"); +}; +xmlhttp.send(); +</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', '#handler-xhr-onloadstart')}}</td> + <td>{{Spec2('XMLHttpRequest')}}</td> + <td>WHATWG 现存标准</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.XMLHttpRequestEventTarget.onloadstart")}}</p> diff --git a/files/zh-cn/web/api/xmlhttprequesteventtarget/onprogress/index.html b/files/zh-cn/web/api/xmlhttprequesteventtarget/onprogress/index.html new file mode 100644 index 0000000000..ad2bced50b --- /dev/null +++ b/files/zh-cn/web/api/xmlhttprequesteventtarget/onprogress/index.html @@ -0,0 +1,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> |