Jul 31, 2007

ASP.NET AJAX WebRequest

            // Instantiate a WebRequest.
            var wRequest = new Sys.Net.WebRequest();

            // Set the request URL.
            wRequest.set_url("getTarget.htm");

            // Set the request verb.
            wRequest.set_httpVerb("GET");

            // Set the request callback function.
            wRequest.add_completed(OnWebRequestCompleted);


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

            // This callback function processes the
            // request return values. It is called asynchronously
            // by the current executor.
            function OnWebRequestCompleted(executor, eventArgs)
            {
            if(executor.get_responseAvailable())
            {
            // Clear the previous results.

            resultElement.innerHTML = "";

            // Display Web request status.
            resultElement.innerHTML +=
            "Status: [" + executor.get_statusCode() + " " +
            executor.get_statusText() + "]" + "
"; // Display Web request headers. resultElement.innerHTML += "Headers: "; resultElement.innerHTML += executor.getAllResponseHeaders() + "
"; // Display Web request body. resultElement.innerHTML += "Body:"; if(document.all) resultElement.innerText += executor.get_responseData(); else resultElement.textContent += executor.get_responseData(); } }