This article is intended to be a simple introduction to AJAX.
This example simply fills a table with values when the user makes a selection. It is intended to illustrate how easy it is to implement custom AJAX into your applications. There are many AJAX libraries available. However, if you have ever tried to customize AJAX to fit your unique application needs, you may have experienced frustration in getting it to do exactly what you needed. AJAX is a very simple technology, but understanding the basic functionality is key when implementing a custom solution. This example is intended to serve that purpose.
Using the code
This project was developed using Visual Studio 2005. The source code is commented and should be easy to follow. There are two ASPX pages in the solution. One is "passer" and the other is "catch." passer.aspx is the page that the user interacts with. catch.aspx is not seen, but prepares the XML and passes it back to passer.aspx.
http_request = new XMLHttpRequest();
http_request = new ActiveXObject("MsXML_Container.XMLHTTP");
http_request = new ActiveXObject("Microsoft.XMLHTTP");
http_request = false;
alert("Error initializing XMLHttpRequest!");
Below, we are creating and defining the parameters to send via URL to catch.aspx before defining the return function:
var url="Catch.aspx?choice=" + document.forms.ddlChoice.value;
http_request.onreadystatechange = ShowResults;
if (http_request.readyState == 4)
var XML_Container =
XML_Container.async = false;
Points of interest
I originally developed this code to populate a datagrid with datasets retrieved from an SQL database via stored procedures. I tried many packaged AJAX libraries, but wasn't able to adapt them to the application's requirements. Learning how AJAX works behind the scenes has been a great help in designing rich user interfaces and fast response times. This example provides a fully (albeit simple) functional example of how AJAX can be used to provide a Desktop Application feel.
Yes, I know, this is a Microsoft IE example. It could, however, easily be modified to work with other browsers. Feel free to e-mail me with any questions, comments and suggestions.
- 9 July, 2007 -- Original version posted