DataQuery is basically a simple wrapper around a XMLHttpRequest, that handles URL structure, error handling and caching transparently.

Contents

[edit] Constructor

new DataQuery (handler, session, arguments, cacheable, ident)
Name Type Required Description
handler String Yes Describes the server handler that will take the request and run it.
session SessionInfo Yes The current authenticated session to use requests with.
arguments Associative array Yes Describes the optional arguments to pass along with the web request to the server as JSON. There are a few parameters that are used directly by the DataQuery object itself. These include:
  • urlargs: URL to append to the end of the original request path. For example, if the original request path is http://mysite.com/sessionid/mail/, the value of urlargs would be appended to that string and used as the URI when the request is run.
cacheable Boolean No Whether or not the result of the DataQuery should be cacheable or not.
ident String No Key used against the arguments parameter to uniquely identify the current DataQuery.

[edit] Properties

[edit] dataComplete

Type: Function
Default: null

Function to run when data query has completed and has data. The function will be run with a single argument, the decoded JSON data.

[edit] dataFailure

Type: Function
Default: null

Function to be run when the data query encounters an error. This can be assumed to be a web-related exception. The function will be called with two arguments, the error code, followed by the error message (en_US only). Please base internationalisable error messages off the error code, rather than the message returned; it should only be used for debugging/testing.

[edit] cacheable

Type: Boolean
Default: false

Whether or not the results from the data request should be cacheable.

[edit] Methods

[edit] run ()

Returns: nothing

Executes the current DataQuery instance asynchronously. Calls dataComplete when the data has been fetched, and dataFailure if there was an error.

A HTTP GET request is performed by the browser's XMLHttpRequest object.

[edit] Example

var q = new DataQuery ("mail", session, { mailbox: "INBOX" };
q.dataComplete = function (msg) { alert (msg); };
q.dataFailure = function (code, msg) { alert ("Error occured: (" + code + "): " + msg); };
q.run (); // run worker async