Datasheet

Chapter 1: AJAX Technologies
6
statusText : This property contains the HTTP status text of the server response. The text
describes the HTTP status code. For example, the status text for status code
200 is OK .
setRequestHeader : This method sets a specified HTTP request header to a specified value. As
such, this method takes two parameters: the first parameter is a string that contains the name of
the HTTP request header whose value is being set, and the second parameter is a string that
contains the value of this HTTP request header.
send : This is the method that actually sends the request to the server. It takes a string parameter
that contains the request body. If you’re making a
GET HTTP request, pass null as the value of
this parameter. If you’re making a
POST HTTP request, generate a string that contains the body
of the request and pass this string into the
send method.
responseText : This property contains the server response in text format.
responseXML : This property contains the server response in XML format (an XML Document to
be exact). This property is set only when the
Content-Type response header is set to the value
text/xml . If the server-side code does not set the response header to this value, the response-
XML
property will be null even when the actual data is in XML format. In such cases, you must
load the content of the
responseText property into an XML document before you can use the
client-side XML API to read the XML data.
The
overrideMimeType property of XMLHttpRequest in Mozilla browsers enables you to override
the MIME type of the server response. However, this is a browser-specific issue that the current discus-
sion does not need to address.
getResponseHeader : This method returns the value of a response header with a specified
name. As such, it takes the name of the response header as its only argument.
getAllResponseHeaders : This method returns the names and values of all response headers.
abort : Use this method to abort a request.
Listing 1-2 presents an example that uses
XMLHttpRequest to make an asynchronous request to the
server. If you access this page, you see the result shown in Figure 1-3 . This page consists of a simple user
interface with two text boxes and a button. If you enter the text “ username ” in the top text box and the
text “ password ” in the bottom text box and then click the button, you get the result shown in Figure 1-4 .
Listing 1-2: A page that uses XMLHttpRequest
<%@ Page Language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
void Page_Load(object sender, EventArgs e)
{
if (Request.Headers[“MyCustomHeader”] != null)
{
if (Request.Form[“passwordtbx”] == “password” &&
Request.Form[“usernametbx”] == “username”)
{
Response.Write(“Shahram|Khosravi|22223333|Some Department|”);
Response.End();
}
else
c01.indd 6c01.indd 6 8/20/07 5:40:04 PM8/20/07 5:40:04 PM