Supplementary

A Small JavaScript-Library that Automates working with XMLHTTPRequest
Objects
and
Types
Name Methods Generated By Description Max Num
XHRFactory

createXHR
createXHRWrapper

Automatic execution
of statically-defined
function
XHRFactory is a singleton factory-object that creates XMLHTTPRequest and XHRWrapper objects. 1
XHRWrapper

doTxn
abort
getXHRObj

XHRFactory An XHRWrapper subsumes an XMLHTTPRequest object, provides a simple interface for working with that object, and automates much of the details of working with XHR. unlimited
Global

xHR_DbC

Platform - 1
*

Response_Handler

User - unlimited
Methods Name Owner Returns Description
createXHR XHRFactory XMLHTTPRequest

Calling this function simply creates an XMLHTTPRequest object that is appropriate to the browser on which the application is running.

It is the responsibility of any client code that calls this function to assign any event handlers to the object returned, as well as to call the open and send methods. Moreover, using this function means that the response handler must check the values of the readyState and status members of the XMLHTTPRequest object itself.

Given that the doTxn method of the XHRWrapper type manages all of these details, there is normally no need to use this method.

createXHRWrapper XHRFactory XHRWrapper Creates an XHRWrapper object.
doTxn XHRWrapper XHRWrapper

This method calls the 'open' and 'send' methods of the XHRWrapper's underlying XHR object, and manages other minutiae associated with this process. It also works around many of the bugs and inconsistencies that the various XHR implementations exhibit.

The method also implements a 'base' response handler that tests the readyState and status attributes of the underlying XHR object each time the server responds.

Given this, client code need not implement this logic itself in the response-handler function that it provides, and given that that function is called only if the transaction with the server was successful, it need contain only the logic needed to process the server's response.

getXHRObj XHRFactory XMLHTTPRequest

This method returns the XMLHTTPRequest object that an XHRWrapper subsumes.

Some implementations of XMLHTTPRequest support methods such as onload, onerror and onprogress, as well as methods for event-listener manipulation. Should client code need to avail itself of these methods then it can do so by retrieving the XHR object that a given wrapper contains.

abort XHRWrapper undefined

Stops a partially-completed transaction with the server.

Calling this function is a safe way of aborting a transaction, in that it ensures that the client-code response handler is not invoked, as happens on certain Gecko-based platforms.

Other than that, it has the same effect as calling the underlying XHR object's abort method, but applications that invoke a transaction using doTxn should use this method to abort that transaction, rather than by retrieving on the underlying XHR object and then calling the abort method on that.

xHR_DbC Global undefined

Uses AspectJS to apply a suffix to createXHRWrapper. That suffix applies a prefix to the doTxn method of any XHRWrapper objects generated thereon, and that prefix checks for bad or missing arguments that client code passes to doTxn. Any such arguments generate an exception, thus alerting developers to incorrect calls.

Any application that uses XHRFactory_DbC must import an instance of the AspectJS AJS-object.

Response_Handler * undefined

Processes the server's response to an XHR transaction. Does not need to test the readyState and status attributes of the XHR object concerned.

Signatures Returns Owner Function Arguments...
XMLHTTPRequest XHRFactory createXHR ( [ CallPoint])
XHRWrapper XHRFactory createXHRWrapper ( [ CallPoint])
undefined XHRWrapper doTxn ( Method, URL [, respHandler [, Data [, ASync [, MimeType [, errHandler [, CallPoint]]]]]])
XMLHTTPRequest XHRWrapper getXHRObj ( [ CallPoint])
undefined XHRWrapper abort ( [ CallPoint])
undefined Global xHR_DbC ( XHRFactory, AJS [, CallPoint])
undefined * Response_Handler ([ XHRObj])
Arguments Name Type Denotes Optional Default Value Can
be
Null
Method string An HTTP method such as 'GET' or 'POST' No - -
URL string A URL No - -
respHandler function A function that is called on successful completion of a transaction Yes Empty function Yes
Data string Data to be sent to server (if appropriate) Yes null Yes
ASync boolean Should the transaction be asynchronous Yes true -
Mimetype string The mimetype of the data being requested Yes Empty string Yes
errHandler function A function that is called when a transaction completes unsuccessfully Yes Empty function Yes
XHRFactory XHRFactory object The XHRFactory object No - -
AJS AJS Object The AspectJS AJS-object No - -
CallPoint string User-defined debugging/profiling data Yes undefined Yes
XHRObj XMLHTTPRequest An XMLHTTPRequest object Yes XMLHTTPRequest Object No
Returns Function Type Denotes Caller
Should
Retain
Can be
Calling-Object
Can
be
Null
createXHR XMLHTTPRequest The XMLHTTPRequest object created Yes No No
createXHRWrapper XHRWrapper The XHRWrapper object created User Decides No No
doTxn undefined - - - -
getXHRObj XMLHTTPRequest The XMLHTTPRequest object subsumed by the XHRWrapper User Decides No No
abort undefined - - - -
xHR_DbC undefined - - - -
Exceptions Function Throw(s) Error Object if... Provisos
createXHR
createXHRWrapper
- -
doTxn

URL argument is undefined
URL argument is null
URL argument is not a string

Method argument is undefined
Method argument is null
Method argument is not a string

respHandler argument does not refer to a function

HTTP method is 'POST' and Data argument is undefined
HTTP method is 'POST' and Data argument is null
Data argument is not a string

ASync argument is null
ASync argument is not a boolean

MimeType argument is not a string

errHandler argument does not refer to a function

Applies only if you
import and call
xHRFactory_DbC into
and within your
application.
abort
getXHRObj
- -
xHR_DbC

XHRFactory argument is undefined
XHRFactory argument is null
XHRFactory argument does not refer to an object

AJS argument is undefined
AJS argument is null
AJS argument does not refer to an object

Object referred to by the AJS argument has no getVersion method
AJS argument does not refer to version 1.1 of the AJS object

Repeated call made to xHR_DbC

Applies only if you
import and call
xHRFactory_DbC into
and within your
application.
Response_Handler

User Decides

-