XHConn - A Simple XMLHTTP Interface Library

XMLHTTP is a technology with which a developer can access external resources over HTTP from a static web page without ever having to reload the page itself. This library is meant to simplify and unify the code necessary to successfully send and receive simple data via XMLHTTP.


The latest version of the code will always be available from this page.

XHConn.js - (1.28KB) - 2005-04-08


XHConn is a data object with a single method. In order to use the object, you must first instantiate a copy of it.

var myConn = new XHConn();

After instantiating the object, it is good practice to check for success and act accordingly.

if (!myConn) // XMLHTTP not available. exit method/handle error.

After you know you have a valid connection to work with, you need to define a function that will fire after your connection is complete. Your function should take a single argument which will be the XMLHttpRequest object with its members intact. [see: XMLHTTPRequest members]

var fnWhenDone = function (oXML) { alert(oXML.responseText); };

Then the final step is to make your actual connection using the connect member function of the XHConn object. The method takes the following arguments:

So a typical function call would look something like this:

myConn.connect("mypage.php", "POST", "foo=bar&baz=qux", fnWhenDone);

At this point your connection will be made and the results will be sent to your function. The two major members of the XMLHTTPRequest object that you will deal with are responseText and responseXML.


You can download this example script file to see what a complete implementation looks like:

testScript.js - (316 bytes) - 2004-08-30


XHConn has been tested on and is compatible with the following browsers: