Jaxer.Callback : Object
Return to: Jaxer Framework index

Callback namespace for remote functions.

Platform Support

Jaxer Server Framework Jaxer Client Framework
no 1.0

Properties

Property Action Jaxer Server Framework Jaxer 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 no 1.0
Visibility
advanced
static METHOD : String
The default HTTP method to use for callback function requests. Initially set to "POST".
No Details no 1.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 no 1.0

Functions

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

(Advanced)
Show Details no 1.0

Returns
String The 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 Details no 1.0

Parameters
Object error If an error was thrown during the request, it would be here.
Object extra Any 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.
XMLHttpRequest xhr The 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 Details no 1.0

Parameters
Error error 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 in during the call to Jaxer.XHR.send() to help identify the request. Currently, there is one String-valued property on this object: functionName.
XMLHttpRequest xhr The 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 Details no 1.0

Parameters
String functionName The name of the function that was called
String rawResult The raw (text) data returned from the XHR call

Returns
Object The 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 Details no 1.0

Parameters
String functionName The name of the remote function
Object args The arguments of the remote function. This can be a single (primitive) object or an array of (primitive) objects
Number initialNumberToSkip (optional)Optionally, how many of the arguments (counting from the beginning) to not pass to the remote function

Returns
String The query string

static formUrlEncode(String str) : String
URL Encode a query string.
Show Details no 1.0

Parameters
String str Query string to be converted.

Returns
String A 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 Details no 1.0

Parameters
Object functionToCall Name of the function (or the function itself) to be called server-side
Object paramsToPass An 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
Object The 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 Details no 1.0

Parameters
Object functionToCall Name of the function (or the function itself) to call server-side
Object paramsToPass An 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
String The 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 Details no 1.0

Parameters
Object hash Hash of name value pairs to be converted.

Returns
String The 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 Details no 1.0

Parameters
String functionName The name of the remote function to call on the server
Object args A single argument, or an array of arguments, to be passed to the remote function on the server

Returns
Object The 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 Details no 1.0

Parameters
Object callback 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.
String functionName The name of the remote function
Object args A 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 Details no 1.0

Parameters
String functionName The name of the remote function to call
Object args A single argument, or an array of arguments, to pass to the remote function
Object callback (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
Object If 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