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.
| Tutorial |
Using createXHR
Retrieving Data
Using Multiple XHRWrappers
xHRFactory_DbC |
| API |
Objects and Types |
| XHR Problems Addressed |
The Firefox synchronous-call anomaly, where the response handler must be executed explicitly after the send call. |
|
The disappearance of the Firefox synchronous-call anomaly in the presence of Firebug (guaranteed to stump you completely when testing on arbitrary Firefox installations). |
|
|
The bug that some browsers exhibit, where a call to an XHR object's abort-method causes a call to the response handler. |
|
|
The XHR-object re-use problem that Internet Explorer exhibits with regard to the point at which the response-handler reference is set. |
|
|
The caching problem that Internet Explorer exhibits. |
|
|
The HTTP header-requirements when using the POST method. |
|
Product Version: 1.2
Tutorial Version: 2.0
API Doc. Version: 2.0