Wednesday, February 1st, 2006

Mike Chambers: Encapsulating Ajax XMLHTTPRequest Calls within JavaScript classes

Category: Ajax, JavaScript, XmlHttpRequest

Mike Chambers has posted a tutorial with code on his blog today concerning combining a set of Ajax (XMLHttpRequest) calls into Javascript classes.

The guys over at Fold posted an article on how to use multiple XMLHTTPRequest (XHR) calls within a single page. This is something that I have had to tackle in my own work, and though I would write up how I solve this issue.

This post describes a simple technique for encapsulating XMLHTTPRequest calls within JavaScript classes. In general, this makes code more maintainable, allows for the creation of easier to use APIs, and makes it much easier to create components / widgets that load data from the server.

In his code, he encapsulates the Ajax instances in a class to make them easier to use and manage. The post steps you through the creation of a simple widget that loads data from an external source and displays it on the page. There are four files involved, including the data file for it to fetch. The code shows how to make a raw XMLHttpRequest call – no external libraries involved, other than the one he provides.

Posted by Chris Cornutt at 1:49 pm
Comment here

3.8 rating from 32 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.