SACK v1.5(Public)

©2005 Gregory Wild-Smith (http://www.twilightuniverse.com/)

This software is distributed under a Modified X11 licence. See distributed doumentation or authors website for more details. If you use this code a link or email would be nice but is not required.

The Simple AJAX Code-Kit (SACK) is a wrapper class designed to make using AJAX simpler, and easy to implement. More information can be found at the authors website.

Last Updated: 1st January 2006

Class Methods

sack (Public)

usage: object sack(string file)

Initialising function for SACK Object.

string file

(optional) The filename of the file to be accessed using XMLHttpRequest. Passes its contents to the requestFile variable.

createAJAX (Private)

usage: void createAJAX()

Constructor function for SACK data. Initialises the XMLHttpRequest object in compatible browsers and if this is not supported sets the failed variable to false.

setVar (Public)

usage: void setVar(string name, string value)

Allows you to add a variable to be parsed into the URLString data in the form of a name/value pair. Does not encode the data.

string name

The name of the data that you want passed to the requestFile.

string value

The corrisponding data that you want passed to the requestFile.

encVar (Private)

usage: string encVar(string name, string value)

Allows you to add a variable to be parsed into the URLString data, in the form of a name/value pair, and URLencodes the data into a unicode compatible escape sequence.

string name

The name of the data that you want passed to the requestFile.

string value

The corrisponding data that you want passed to the requestFile.

processURLString (Private)

usage: string processURLString(string string, boolean encode)

Splits up an URLString formatted string, and passes the name/value pairs to the variable setting functions.

string string

The name of the data that you want passed to the requestFile.

boolean encode

If the passed string should be encoded.

createURLString (Public)

usage: void createURLString(string urlstring)

Creates a correctly formatted URLString from any existing and/or passed data.

string urlstring

(optional) A correctly formatted URLstring which will be added to the existing variable data (if any).

runResponse (Public)

usage: void runResponse()

Evaluates the response text as javascript commands, and runs any present.

resetData (Public)

usage: void resetData()

Resets all the library variables back to their default values.

resetFunctions (Public)

usage: void resetFunctions()

Resets the onEvent functions back to their default state.

reset (Public)

usage: void reset()

Runs both resetData and resetFunctions. Effectively resets all data to the same as when the original object was initialised.

runAJAX (Public)

usage: string runAJAX(string urlstring)

Runs the AJAX request. And fills class variables with appropriate responses (response, responseXML, responseStatus, etc). If the encodeURIString variable is set to true (default) then will escape the name/value pairs in the URLstring variable. If an element has been set then the elements contents (innerHTML or value) will be replaced. If the execute variable is set to true then will call the runResponse method.

string urlstring

(optional) A string of name/value pairs formatted in the GET URL String style (eg: var1=data1&var2=data2).

Class Variables

(String) AjaxFailedAlert - Holds a warning that will be used to alert users that their browser does not support XMLHttpRequest. To turn off warning set to null. Has a default message.

(String) requestFile - Holds the file that the request will be sent to.

(String) method - The http method used to communicate with the file, can be any valid method though GET and POST will probably be most common. Defaults to POST.

(String) element - The element to replace the contents of with the response text. Is not set by default.

(String) URLString - List of variables and values in GET style format name/value pairs seperated by &'s.

(Boolean) encodeURIString - Whether to escape the data in the string. Set to false if you do this yourself, or use only ASCII characters. Defaults to true.

(Boolean) execute - Set to true if you want to evaluate the response text as if it was javascript code, and run it. Defaults to false.

(function) onLoading - Pass this variable a javascript function without arguments that you wish to run when Loading.

(function) onLoaded - Pass this variable a javascript function without arguments that you wish to run when Loaded.

(function) onInteractive - Pass this variable a javascript function without arguments that you wish to run when Interactive (data is being streamed).

(function) onCompletion - Pass this variable a javascript function without arguments that you wish to run when Completed.

(function) onError - Pass this variable a javascript function without arguments that you wish to run when the response code from the server is not 200 (i.e. there has been an error or problem).

(Array) responseStatus - Array of the response status returned. 0 index is the response code (eg 404, 300, etc) and the 1 index is the text description.

(Boolean) failed - Allows you to detect if the software supports XMLHttpRequest (true) or not (false).

(String) response - The response text recieved from the server.

(String) responseXML - The response xml revieved from the server.

(Array) vars - Holds data to be passed (via the URL String) to the server. Uses the name from the name/value pair as the array key. Also holds the encoded state of the data.