更新:2007 年 11 月
停止由执行器发出的挂起的网络调用。
MyExecutor.abort();
异常
异常类型 |
条件 |
|---|---|
执行器未启动,因此无法停止。 |
备注
在停止 Web 请求后,取消挂起的超时计时器。
调用 abort 时,执行器将 aborted 属性设置为 true。这意味着 XmlHttpExecutor 实例的 get_started 和 get_aborted 方法都返回 true。
然后 WebRequestManager 实例调用关联请求对象的完成事件处理程序。调用 abort 方法后,执行器的方法返回的响应状态为未定义。
可以多次调用 abort 方法。但是,不会处理第二次及后续调用。仅引发一次完成事件处理程序。
如果先调用 abort 方法再调用 executeRequest 方法前,将引发异常。
示例
下面的示例演示如何使用 abort 方法停止 Web 请求。此代码摘自 Sys.Net.XmlHttpExecutor 类概述中的一个完整示例。
// This function aborts a Web request.
function AbortWebRequest()
{
// Create the WebRequest object.
wRequest = new Sys.Net.WebRequest();
// Set the request Url.
wRequest.set_url("getTarget.htm");
// Clear the results area.
resultElementId.innerHTML = "";
// Set the Completed event handler,
// for processing return data
wRequest.add_completed(OnCompleted);
// Make the request.
wRequest.invoke();
// Get the current executor.
var executor = wRequest.get_executor();
// Abort the request.
executor.abort();
// Check if the executor is aborted.
var execAborted =
executor.get_aborted();
alert("Executor aborted: " + execAborted);
}