如何判断是否在XMLHTTPRequest上调用了“abort()”

时间:2022-10-08 12:53:56

Simple question, but not obvious from the Mozilla JS docs. Anyone know the answer off the top of their head?

简单的问题,但从Mozilla JS文档中并不明显。任何人都知道他们头顶的答案?

2 个解决方案

#1


Here's the standard implementation. Based on below, the only way is to check the readyState of the object, however this won't work in all browsers.

这是标准实现。基于下面,唯一的方法是检查对象的readyState,但是这不适用于所有浏览器。

Syntax

XMLHttpRequest.abort() Return Value

XMLHttpRequest.abort()返回值

No return value.

没有回报价值。

Remarks

abort was introduced in Windows Internet Explorer 7.

在Windows Internet Explorer 7中引入了abort。

The abort method interrupts an asynchronous operation in progress. (Pass true to the varAsync parameter of open to create an asynchronous request.)

中止方法中断正在进行的异步操作。 (将true传递给open的varAsync参数以创建异步请求。)

Calling abort resets the object; the onreadystatechange event handler is removed, and readyState is changed to 0 (uninitialized).

调用中止会重置对象;删除onreadystatechange事件处理程序,readyState更改为0(未初始化)。

Source

#2


W3C Spec, "The XMLHttpRequest Object":

W3C Spec,“XMLHttpRequest对象”:

http://www.w3.org/TR/XMLHttpRequest/

Shortcut to the abort() method:

abort()方法的快捷方式:

http://www.w3.org/TR/XMLHttpRequest/#abort

Under the heading "Exceptions for the XMLHttpRequest Object" it says this:

在“XMLHttpRequest对象的例外”标题下,它说:

The ABORT_ERR exception is raised when the user aborts a request in synchronous requests.

当用户在同步请求中中止请求时,将引发ABORT_ERR异常。

#1


Here's the standard implementation. Based on below, the only way is to check the readyState of the object, however this won't work in all browsers.

这是标准实现。基于下面,唯一的方法是检查对象的readyState,但是这不适用于所有浏览器。

Syntax

XMLHttpRequest.abort() Return Value

XMLHttpRequest.abort()返回值

No return value.

没有回报价值。

Remarks

abort was introduced in Windows Internet Explorer 7.

在Windows Internet Explorer 7中引入了abort。

The abort method interrupts an asynchronous operation in progress. (Pass true to the varAsync parameter of open to create an asynchronous request.)

中止方法中断正在进行的异步操作。 (将true传递给open的varAsync参数以创建异步请求。)

Calling abort resets the object; the onreadystatechange event handler is removed, and readyState is changed to 0 (uninitialized).

调用中止会重置对象;删除onreadystatechange事件处理程序,readyState更改为0(未初始化)。

Source

#2


W3C Spec, "The XMLHttpRequest Object":

W3C Spec,“XMLHttpRequest对象”:

http://www.w3.org/TR/XMLHttpRequest/

Shortcut to the abort() method:

abort()方法的快捷方式:

http://www.w3.org/TR/XMLHttpRequest/#abort

Under the heading "Exceptions for the XMLHttpRequest Object" it says this:

在“XMLHttpRequest对象的例外”标题下,它说:

The ABORT_ERR exception is raised when the user aborts a request in synchronous requests.

当用户在同步请求中中止请求时,将引发ABORT_ERR异常。