Jaxer.Callback : Object
Return to: Jaxer Framework index

Callback namespace for remote functions.

Platform Support

Jaxer Server FrameworkJaxer Client Framework
no1.0

Properties

PropertyActionJaxer Server FrameworkJaxer Client Framework
static POLLING_PERIOD : Number
The default polling interval used to see whether the XMLHttpRequest for an async callback function call has returned. Initially set to 11.

(Advanced)
No Details no1.0
Visibility
advanced
static METHOD : String
The default HTTP method to use for callback function requests. Initially set to "POST".
No Details no1.0
static TIMEOUT : Number
The default number of milliseconds to wait before timing out an async callback function request. Initially set to 10 * 1000 (10 seconds).
No Details no1.0

Functions

MethodActionJaxer Server FrameworkJaxer Client Framework
static getBaseUrl() : String
Returns the URL for use in callbacks, without any parameters

(Advanced)
Show Detailsno1.0

Returns
StringThe URL to GET or POST to

static onfailureAsync(Object error, Object extra, XMLHttpRequest xhr) : void
The default method used to handle errors when calling remote functions asynchronously. It alerts the error message if Jaxer.ALERT_CALLBACK_ERRORS is true, and in any case throws an error

(Advanced)
Show Detailsno1.0

Parameters
ObjecterrorIf an error was thrown during the request, it would be here.
ObjectextraAny extra information passed in during the call to Jaxer.XHR.send() to help identify the request. Currently, there is one String-valued property on this object: functionName.
XMLHttpRequestxhrThe XMLHttpRequest object that encountered the error. This might be null, if an error was encountered in creating the XMLHttpRequest.

static ontimeoutAsync(Error error, Object extra, XMLHttpRequest xhr) : void
The default method used to handle timeouts when calling remote functions asynchronously. It alerts the error message if Jaxer.ALERT_CALLBACK_ERRORS is true, and in any case throws an error

(Advanced)
Show Detailsno1.0

Parameters
ErrorerrorThe timeout error object encountered, having a "timeout" property with its value indicating the timeout (in milliseconds) used in this request.
ObjectextraAny extra information passed in during the call to Jaxer.XHR.send() to help identify the request. Currently, there is one String-valued property on this object: functionName.
XMLHttpRequestxhrThe XMLHttpRequest object that encountered the error.

static processReturnValue(String functionName, String rawResult) : Object
Transforms the raw result data from the XHR call into the expected data format.

(Advanced)
Show Detailsno1.0

Parameters
StringfunctionNameThe name of the function that was called
StringrawResultThe raw (text) data returned from the XHR call

Returns
ObjectThe returned data in the format the remote function returned it

static createQuery(String functionName, Object args, [Number initialNumberToSkip]) : String
Creates a query string for calling a remote function with the given arguments
Show Detailsno1.0

Parameters
StringfunctionNameThe name of the remote function
ObjectargsThe arguments of the remote function. This can be a single (primitive) object or an array of (primitive) objects
NumberinitialNumberToSkip(optional)Optionally, how many of the arguments (counting from the beginning) to not pass to the remote function

Returns
StringThe query string

static formUrlEncode(String str) : String
URL Encode a query string.
Show Detailsno1.0

Parameters
StringstrQuery string to be converted.

Returns
StringA URL-encoding string

static getQueryParts(Object functionToCall, Object paramsToPass, String ...) : Object
Returns a hash of the "form-like" name-value pairs needed to call a JavaScript function on the server. These can be submitted to the server as a GET request (but see Callback.getUrl which wraps this in a Url for you) or as a POST request, and usually via an XMLHttpRequest mechanism.

The server listens for two special name-value pairs: "resultAs" and "paramsAs".

If present, resultAs specifies how the result of functionToCall is to be returned to the client. Valid values for resultAs are "text", "object", and "wrappedObject" (default), which return the result of the callback as a single string, a JSON object literal, or a JSON object literal with metadata, respectively.

If present, "paramsAs" specifies how the request is to be translated into arguments for the functionToCall. Valid values for "paramsAs" are "text", "object", and "default", which hands the GET or POST data to functionToCall as a single string, a single hash (object literal) of name-value pairs, or as regular JavaScript arguments with values extracted from paramsToPass, respectively.
Show Detailsno1.0

Parameters
ObjectfunctionToCallName of the function (or the function itself) to be called server-side
ObjectparamsToPassAn array of parameters (or the single parameter) to pass to the function
String...Optional parameter(s) to append to the end of the URL as part of the query string. String arguments should be "name=value" pairs joined by "&" characters. If arguments are a hash, their properties are added to the hash.

Returns
ObjectThe hash of the information needed to invoke the function

static getUrl(Object functionToCall, Object paramsToPass, String ...) : String
Returns the URL that can be used as a GET request to call a JavaScript function on the server.

The server listens for two special properties: "resultAs" and "paramsAs".

If present, resultAs specifies how the result of functionToCall is to be returned to the client. Valid values for resultAs are "text", "object", and "wrappedObject" (default), which return the result of the callback as a single string, JSON object literal, or JSON object literal with metadata, respectively.

If present, "paramsAs" specifies how the request is to be translated into arguments for the functionToCall. Valid values for "paramsAs" are "text", "object", and "default", which hands the GET or POST data to functionToCall as a single string, a single hash (object literal) of name-value pairs, or as regular JavaScript arguments with values extracted from paramsToPass, respectively.
Show Detailsno1.0

Parameters
ObjectfunctionToCallName of the function (or the function itself) to call server-side
ObjectparamsToPassAn array of parameters (or the single parameter) to pass to the function
String...Optional parameter(s) to append to the end of the URL as part of the query string. Strings will be appended to the end of the URL separated by a "&". Hashes will be appended as &name1=value&name2=value2...

Returns
StringThe URL that can be called (via a GET) to invoke the function

static hashToQuery(Object hash) : String
Converts a javascript object (hash) into a http query string.
Show Detailsno1.0

Parameters
ObjecthashHash of name value pairs to be converted.

Returns
StringThe query string

static invokeFunction(String functionName, Object args) : Object
This method invokes a synchronous call to a proxied JavaScript function on the server from the client side javascript.
Show Detailsno1.0

Parameters
StringfunctionNameThe name of the remote function to call on the server
ObjectargsA single argument, or an array of arguments, to be passed to the remote function on the server

Returns
ObjectThe value returned by the remote function on the server

static invokeFunctionAsync(Object callback, String functionName, Object args) : void
This method invokes an asynchronous call to a proxied javascript function on the server from the client side javascript. A callback function needs to be provided and is called once the XHR request completes or times out.
Show Detailsno1.0

Parameters
ObjectcallbackIf this is a function, this is the function to call upon a successful return from the remote invocation. Its arguments are what the remote function on the server returned.

If this is an array, its elements are as follows (each may be null):
  1. the callback function;
  2. a function to call on an error, with arguments being the error, the "extra" information object that has the functionName as its one property, and the XMLHttpRequest object used for the call if the call itself encountered an error;
  3. the timeout to use, in milliseconds (defaults to Jaxer.Callback.TIMEOUT). Use 0 to wait indefinitely.


If this is an object, its "callback", "errorHandler", and timeout properties will be used, if any.
StringfunctionNameThe name of the remote function
ObjectargsA single argument, or an array of arguments, to be passed to the remote function on the server

static remote(String functionName, Object args, [Object callback]) : Object
A short convenience function to call a remote function, synchronously or asynchronously based on whether or not you specify a callback function as the third argument.
Show Detailsno1.0

Parameters
StringfunctionNameThe name of the remote function to call
ObjectargsA single argument, or an array of arguments, to pass to the remote function
Objectcallback(optional)If this is not specified, the call will be synchronous.
If this is specified, the call will be asynchronous.

If this is a function, this is the function to call upon a successful return from the remote invocation. Its arguments are what the remote function on the server returned.

If this is an array, its elements are as follows (each may be null):
  1. the callback function;
  2. a function to call on an error, with arguments being the error, the "extra" information object that has the functionName as its one property, and the XMLHttpRequest object used for the call if the call itself encountered an error;
  3. the timeout to use, in milliseconds (defaults to Jaxer.Callback.TIMEOUT). Use 0 to wait indefinitely.


If this is an object, its "callback", "errorHandler", and timeout properties will be used, if any.

Returns
ObjectIf synchronous, the value returned by the remote function; if asynchronous, an id by which the remote call can be canceled via Jaxer.XHR.cancel()

aptana_docs