Sys.Net.WebRequest add_completed Method
Registers a handler for the completed request event of the Web request.
The function registered to handle the completed request event.
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.
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.
// This function adds and removes the
// Web request completed event handler.
// Instantiate the WebRequest.
var wRequest = new Sys.Net.WebRequest();
// Set the request Url.
// Set the web request completed event handler,
// for processing return data.
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.
alert("Removed handler; the Web request return is not processed.");
// Execute the request.