Activate your free membership today | Log-in

Wednesday, February 1st, 2006

Mike Chambers: Encapsulating Ajax XMLHTTPRequest Calls within JavaScript classes

Category: Ajax, JavaScript, XmlHttpRequest

<>p> 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.

Related Content:

  • Ajax Web application development celebrates fifth anniversary
    The term "Ajax" was first used five years ago in a blog entry by Jesse James Garret. We spoke with Garret and other Ajax pioneers and users about the...
  • Book excerpt: Using the Ajax.NET Pro Library
    This chapter looks at the Ajax.NET Professional Library, an open-source framework that saves .NET developers from rewriting code to make it available...
  • Ajax Learning Guide
    Are you a Web developer? The time has come to rethink your entire approach to developing Web applications. Find out about the Ajax approach...
  • Ajax Learning Guide
    Are you a Web developer? The time has come to rethink your entire approach to developing Web applications. Find out about the Ajax approach...
  • Ajax (Asynchronous JavaScript and XML)
    Ajax (Asynchronous JavaScript and XML) is a method of building interactive applications for the Web that process user requests immediately. Ajax...

Posted by Chris Cornutt at 1:49 pm
Comment here

+++--
3.9 rating from 27 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.