Mike Levin SEO

Future-proof your technology-skills with Linux, Python, vim & git... and me!

XMLHttpRequest Object Example

by Mike Levin SEO & Datamaster, 08/05/2005

OK, so I’ve been researching and using Ajax libraries such as OpenRico and SAJAX. But at its heart, it’s just using the XMLHttpRequest object, which was originally a feature of just MSIE, because it was a feature of the Microsoft XML parser, MSXML. But since Google Maps, and a few other innovations, the browser community at large has been forced to support it. I’ve gravitated towards the OpenRico Ajax library, because it’s being driven by Ruby on Rails development, and I’m very interested in ROR. But I want to know what’s going on underneath. And the WebReference people just put out “How to Develop Web Applications with Ajax, Pt. 1”. There is a lot in their example about the event handling, but I’m most interested for now in just how to access the XMLHttpRequest object on different browsers. That’s shown right at the beginning of their example…

if(window.XMLHttpRequest){ xmlObj = new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlObj = new ActiveXObject(“Microsoft.XMLHTTP”); } else { return; }

So now you have access to an XML object for further manipulation. It appears almost straight forward enough that you don’t need an Ajax library. But I’m going to continue using one to simplify coding that much more. I want to focus on the events and the XML payloads.

I’m thinking through the next step on the big project. I was amused to find that my last crack at this project under ASP.NET has been characterized as a massive effort, and how I got back to that same point almost instantly under VBScript and Ajax. It’s to the credit of the “language you know” vs. the next oversized framework claiming to make your work easier, if you only buy into all the wrong philosophies. Specifically, I want to implement this superior web user interface with everything Ajax has to offer. I’m even considering keeping the preview-pane in an iframe, so I don’t have to worry about forced vertical scrolling.

I have one more example to make, which ties all my tests so far together, and wires it to a live application. I actually released this real-time search engine data from Mike-Levin.com in order to have a table with lots of records that I can wire this example to. It will be a great example of surfing through a table with potentially millions of records, without any serious performance penalty.

Since I made my first OpenRico Example post, I’ve been coming up very high in Google for people looking for examples. I think that is a good thing, because I distilled it down to the bare essence example, and dealt with two annoying issues that you are bound to encounter.