Simple AJAX Code-Kit (SACK)
The Simple AJAX Code-Kit (SACK) is a wrapper class designed to make using AJAX simpler, and easy to implement.
Licenses:
This software is distributed under a Modified X11 licence.
There are two basic elements to this code-kit: Class variables and Class Methods.
Demo page
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.
(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.
Class Methods
usage: object sack(string file)
(Public) 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.
usage: void createAJAX()
(Private) Constructor function for SACK data. Initialises the XMLHttpRequest object in compatible browsers and if this is not supported sets the failed variable to false.
usage: void setVar(string name, string value)
(Public) Allows you to add to 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.
usage: string encVar(string name, string value)
(Private) Encodes data, passed in the form of a name/value pair, into a unicode compatible escape sequence. Returns the encoded pair.
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.
usage: string encodeURLString(string string)
(Private) Encodes data, passed in the form of a name/value pair, into a unicode compatible escape sequence.
string string: The name of the data that you want passed to the requestFile.
usage: void runResponse()
(Public) Evaluates the response text as javascript commands, and runs any present.
usage: string runAJAX(string urlstring)
(Public) 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).
Show (1) - Add comments:
|
Comments
Posted by carlos, on 11/26/2005 at 12:37 1 Page 1 of 1 ( 1 Comments )
You are not authorized to leave comments. Please login first. |
|