W3 Teck's Quick & Dirty Ajax Handler

When I first tried my hand at Ajax all I needed was a simple tool that would handle making the connection to the server and receiving the response. I knew JavaScript and really had no need of a tool that would do more than this simple basic function. I looked for some existing tool to do the job, but had little luck. When I found something simple it could not handle multiple, simultaneous requests. On the other end of the spectrum were the Ajax frameworks that tried to be everything to everyone and as a result you basically needed to learn a completely new language to understand how to use if. While written in JavaScript, most of the tools available have their own rules and syntax. They have ceased to be JavaScript. This is because the people that write such tools have in essence created their own sub-language.

I don't know how it is with other developers, but I simply do not have the time to learn all the obscure classes, functions, and what-have-you to become efficient with the use of such frameworks. I know JavaScript and I really don't need a tool so that I can use it. What I need are tools that will make my job easier, make me more efficient and help me get the job done. If I have to spend a week or more learning how to use something new then I've just wasted that time and in most cases I could have simply written something myself in less time.

Finally, I just wrote something myself. The result is this very small Javascript class. It does exactly one thing, and only one thing, it handles the communication with the server. That is, it makes a connection to a server, sends a request to the server and receives the response. Unlike the other frameworks available out there, this tool does very little, but it does exactly what I need it to do.

Before you even look at the tool, do not expect that it will handle more than what is stated above. To use it you must write the functions that will call the class and then you must write the functions that deal with what is returned from the server. But, if you, like me, know JavaScript well enough that these tasks are not an issue, then you may want to give this a try. The code is well documented with explanations detailing all of the parameters and how to write simple functions to use the class.

The class can handle multiple simultaneous connections. As far as I know there are no limits to the number outside of the number of connections that a browser itself is allowed to have open.

As a final note I would like to say a word about the function names. The class is named hajax and all of the functions in it begin with hajax_. The reason this was done was to avoid conflicts with other javascript functions. I have not seen any other scripts that use this name. Unlike some of the frameworks where they all seem to use the same name "ajax".

If you find this script useful, please let me know and if you have the inclination, a link back to this page would be greatly appreciated. Also, if you have any input about this script, please let me know that as well. I am not against making improvements in it as long as these improvements do not change the original goal I had when I wrote it of performing only the single task of communicating with the server.

New - 2008/07/06

I have added two ways to block multiple simultaneous requests.

  1. The first is the ability to disable all simultaneous requests. This will turn the ability of the class to perform more than a single connection at a time.
  2. The second temporarily blocks additional requests through a parameter in the function call.
  3. I have also added some documentation at the end of the file on how to disallow multiple simultaneous requests on a function-by-funtion basis.

These additions were made because there was a need that they be implemented and because it fit in with my goal for this class of only doing a single function (performing comunication with the server) and doing it well.

Download Hajax Ajax Class (Downloads: 89)

I am still open to suggestions on how this class may be improved. If you have any problems with it, or you find something that you think it should do but doesn't, drop me a line and tell me about it. As long as the modification does not change the original goal of the script I will very likely take it into consideration.

;