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.WebRequest add_completed Method

Registers a handler for the completed request event of the Web request.

Syntax

MyWebRequest.add_completed(handler);

Arguments

Term

Definition

handler

The function registered to handle the completed request event.

Remarks

The executor associated with the Web request raises the completed request event by calling the completed method. The handler function is called to process returned data when the work being performed by the associated executor is finished. Note that completion does not signify success. An executor finishes its work in one of three states: completed, aborted, or timed out.

The registered event handler function must accept two parameters:

  • A reference to the executor that issued the network request. You can access the executor to check its status and to retrieve the response data.

  • An eventArgs parameter that is set by the executor that raised the completed request event. For default executors, this argument is set to NIB: empty Property.

The event handler can determine the state of the executor by using one of the following executor properties: responseAvailable, aborted, or timedOut.

The event handler can access other response information about the executor only if responseAvailable returns true.

Example

The following example shows how to add and remove the completed event handler. This code is part of a complete example found in the WebRequest class overview.

javascript

// This function adds and removes the 
// Web request completed event handler.
function WebRequestCompleted()
{    
    // Instantiate the WebRequest.
    var wRequest =  new Sys.Net.WebRequest();

    // Set the request Url.  
    wRequest.set_url(getPage);  

    // Set the web request completed event handler,
    // for processing return data.
    wRequest.add_completed(OnWebRequestCompleted);   
    alert("Added Web request completed handler");

    // Remove the web request completed event handler.
    // Comment the following two lines if you want to
    // use the handler.
    wRequest.remove_completed(OnWebRequestCompleted); 
    alert("Removed handler; the Web request return is not processed.");

    // Execute the request.
    wRequest.invoke();  
}