Supplementary

A Small JavaScript-Library that Automates working with XMLHTTPRequest

The XMLHTTPRequest class underpins the majority of AJAX techniques in web development, but working with it entails certain complexities and considerations. This section presents a small and very simple JavaScript library that automates the creation and use of XHR objects.

The library comprises two components. The first of which - XHRFactory - is a singleton factory-object that exposes just two methods called createXHR and createXHRWrapper. createXHR creates raw XMLHTTPRequest objects (very efficiently) that are appropriate to the platform in question, but which require the application to manage all aspects of transacting with the server.

In contrast, createXHRWrapper creates 'XHRWrapper' objects that subsume an XHR object, and which automate the transaction process completely. XHRWrappers also absolve developers of managing the (completely needless, and thoroughly annoying) bugs, inconsistencies and anomalies that the various XHR-implementations exhibit.

As with the AspectJS AJS-object, and all the other libraries available here, XHRWrapper object-methods do not check the type, number and value of parameters passed by their callers. Instead, the library's second component comprises an optional adjunct called xHR_DbC ('XMLHTTPRequest Design by Contract'), which uses the AJS object to implement error checking on an as-needed and maximally efficient basis.