Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Sys.Net.XmlHttpExecutor abort Method

Stops the pending network call issued by the executor.

Syntax

MyExecutor.abort();

Exceptions

Exception Type Condition

InvalidOperationException

The executor was not started and can therefore not be stopped.

Remarks

After a Web request is stopped, the pending time-out timer is canceled.

When abort is called, the executor sets the aborted property to true. This means that the get_started and get_aborted methods of the XmlHttpExecutor instance both return true.

The WebRequestManager instance then calls the completed event handler of the associated request object. After the abort method is called, the state of the response returned by the executor's methods is undefined.

You can call the abort method multiple times. However, the second and subsequent calls are not processed. The completed event handler is raised only one time.

If you call the abort method before you call the executeRequest method, an exception is thrown.

Example

The following example shows how to stop a Web request using the abort method. This code is part of a complete example found in the Sys.Net.XmlHttpExecutor class overview.

JavaScript

// 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);
}