Recently, while researching how to get information from the server without unloading and reloading the page, I read about the XMLHTTP ActiveX object. Essentially, this object provides a way for Internet Explorer to communicate with the Web server and receive a response. It is part of the MSXML dynamic load library, which is currently at version 4 and is available as a free download from Microsoft. It is also important to note that the default version of MSXML for Microsoft Internet Explorer 5.x is version 2.
Implementing XMLHTTP objects
Whenever I start trying to implement a concept or feature I've never tried before, I usually find it easier to break the problem into logical pieces. In this case, I started with the server-side piece and client-side pieces. With this in mind, the server-side Active Server Page, which I’ll call test.asp, looks something like this:
<%@ Language=VBScript %>
The purpose of this server-side snippet is to return the value for any ASP session variable associated with the key in the query string.
The next step
To further examine the possibilities of XMLHTTP, however, it is necessary to take a step backward because of a limitation in the URL used to convey the query string information from the client to the server. URLs are limited to a maximum of 2,048 bytes. This 2-KB maximum also includes the nonquery string portion of the URL. To go further, it is necessary to find a better way to pass information from the client to the server.
It took me a only about 20 minutes to come to a decision on how I would pass information from the client to the server. I decided to use HTTP. Before you decide that my mind has wandered and has yet to return, let me explain. I would pass the information in the HTTP header. By passing it in the header, it is possible to avoid the 2,048-byte limitation that is inherent in using the URL to pass information.
With this in mind, it is now necessary to modify the examples to pass information via the URL. On the client side, instead of adding a parameter to the URL of test.asp, the XMLHTTP object’s setHeader method would pass the parameter. Applying this modification produces the client-side routine shown in Listing B.
On the server side, it is necessary to retrieve the session variable name from the HTTP header instead of the request object’s query string. The result is:
<%@ Language=VBScript %>
Way beyond the basics
The name of the object I’ve described here is XMLHTTP. Note the first three letters of the object’s name: XML. You’ve seen here how to pass information between the client and the server, but the intended purpose of the XMLHTTP object is to allow the passing of information between the client and the server as XML. In a future article, I’ll explain how to use the XML Simple Object Access Protocol (SOAP) to exchange more complex information.