Jaxer.XHR : Object
Return to: Jaxer Framework index

Namespace to hold the Jaxer client-side cross-browser wrapper around XMLHttpRequest.

Platform Support

Jaxer Server Framework Jaxer Client Framework
1.0 1.0

Properties

Property Action Jaxer Server Framework Jaxer Client Framework
static REASON_FAILURE : String
The value of the "reason" property that indicates a communication failure has occurred. This property is set on the Error object that's thrown by XHR.send() during synchronous requests that don't use the onsuccess function but rather just return a response or throw an Error.

(Advanced)
No Details 1.0 1.0
Visibility
advanced
static REASON_TIMEOUT : String
The value of the "reason" property that indicates a timeout has occurred. This property is set on the Error object that's thrown by XHR.send() during synchronous requests that don't use the onsuccess function but rather just return a response or throw an Error.

(Advanced)
No Details 1.0 1.0
Visibility
advanced
static defaults : Jaxer.XHR.SendOptions
The default SendOptions which new calls to Jaxer.XHR.send(message, options, extra) will use, unless overridden by the options argument. This is slightly different for client-side and server-side requests (e.g. server-side requests are by default synchronous).
No Details 1.0 1.0

Functions

Method Action Jaxer Server Framework Jaxer Client Framework
static getTransport() : XMLHttpRequest
Returns an XMLHttpRequest object by calling the platform-specific API for it. On the server side of Jaxer, the XPCOM version of XMLHttpRequest is used.

(Advanced)
Show Details 1.0 1.0

Returns
XMLHttpRequest

static onfailure(Object error, Object extra, XMLHttpRequest xhr) : void
The default client-side function used to handle any errors that occur during XMLHttpRequest processing by throwing an error describing them

(Advanced)
Show Details 1.0 1.0

Parameters
Object error An error object describing the error, if one was thrown. Otherwise this is null.
Object extra Any extra information passed into Jaxer.XHR.send(), e.g. to make error messages more informative.
XMLHttpRequest xhr The XMLHttpRequest object that contains the information received from the server, e.g. in xhr.status and xhr.responseText. It may be null if an error was encountered creating it.

static ontimeout(Error timeout, Object extra, XMLHttpRequest xhr) : void
The default client-side function used to handle any timeout errors that occur during XMLHttpRequest processing by throwing an error describing them

(Advanced)
Show Details 1.0 1.0

Parameters
Error timeout The timeout error object encountered, having a "timeout" property with its value indicating the timeout (in milliseconds) used in this request.
Object extra Any extra information passed into Jaxer.XHR.send(), e.g. to make error messages more informative.
XMLHttpRequest xhr The XMLHttpRequest object that contains the information received from the server, e.g. in xhr.status and xhr.responseText. It may be null if an error was encountered creating it.

static testSuccess(XMLHttpRequest xhr) : Boolean
The default function used to test whether the XMLHttpRequest got a successful response or not, in particular using xhr.status, location.protocol and some browser sniffing.

(Advanced)
Show Details 1.0 1.0

Parameters
XMLHttpRequest xhr The XMLHttpRequest object that got the response

Returns
Boolean true if successful, false otherwise

static cancel(Number asyncKey) : Boolean
Cancels the pending async XMLHttpRequest if its response has not yet been received and if it has not yet timed out.
Show Details 1.0 1.0

Parameters
Number asyncKey The key that Jaxer.XHR.send() returned when the request was created.

Returns
Boolean true if the request was found and canceled, false if it was not found (i.e. was not in the pending queue)

static send(String message, Object options, Object extra) : Object
The generic function used to send requests via XMLHttpRequest objects. Each request gets its own XMLHttpRequest object, and async requests hold onto that object until they're finished or timed out or canceled. On the server side of Jaxer, only synchronous requests are supported.

For async requests, this returns a key that can be used to abort the request via Jaxer.XHR.cancel().

For synchronous requests, returns the response of the server or throws an exception if an error occurred, unless an onsuccess function was specified in the options, in which case it passes the response to that function and also handles any errors through the onfailure function if specified in the options.

In any case, the response can be a text string or an XML DOM. To force one or the other, set the "as" property on the options argument, e.g. if as="text" it will definitely be a text string, if as="xml" it will definitely be an XML DOM, and if as="e4x" it will be an E4X DOM (if E4X is supported -- which is always the case server-side but may not be client-side).
Show Details 1.0 1.0

Parameters
String message The message to send, usually as a query string ("name1=value&name2=value2...")
Object options A JavaScript object (hashmap) of name: value property pairs specifying how to handle this request.
Object extra Any extra information that might be useful e.g. in the error handlers on this request. This object is simply passed on to them if/when they're called. E.g. Jaxer.Callback uses this information to pass the name of the function being called remotely, so error messages can be more informative.

Returns
Object For async requests, a key to the XHR object; for synchronous requests (with no onsuccess handler in the options), a text string or an XML DOM, or an object containing detailed information about the response (if the options specified extendedResponse=true)

aptana_docs