Ajax.js

Contains the Ajax class.  Also contains methods to generate querystings from forms and Objects.

Credits

Loosely based on the version from prototype.js http://prototype.conio.net

License

MIT-style license.

Summary
Ajax.jsContains the Ajax class.
AjaxAn Ajax class, For all your asynchronous needs.
Properties
requestExecutes the ajax request.
evalScriptsExecutes scripts in the response text
getHeaderReturns the given response header or null
Object related Functions
Functions
Object. toQueryStringGenerates a querystring from key/pair values in an object
ElementCustom class to allow all of its methods to be used with any DOM element via the dollar function $.
Properties
sendSends a form with an ajax post request

Ajax

An Ajax class, For all your asynchronous needs.  Inherits methods, properties, options and events from XHR.

Arguments

urlthe url pointing to the server-side script.
optionsoptional, an object containing options.

Options

datayou can write parameters here.  Can be a querystring, an object or a Form element.
update$(element) to insert the response text of the XHR into, upon completion of the request.
evalScriptsboolean; default is false.  Execute scripts in the response text onComplete.  When the response is javascript the whole response is evaluated.
evalResponseboolean; default is false.  Force global evalulation of the whole response, no matter what content-type it is.

Events

onCompletefunction to execute when the ajax request completes.

Example

var myAjax = new Ajax(url, {method: 'get'}).request();
Summary
Properties
requestExecutes the ajax request.
evalScriptsExecutes scripts in the response text
getHeaderReturns the given response header or null

Properties

request

Executes the ajax request.

Example

var myAjax = new Ajax(url, {method: 'get'});
myAjax.request();

OR

new Ajax(url, {method: 'get'}).request();

evalScripts

Executes scripts in the response text

getHeader

Returns the given response header or null

Object related Functions

Summary
Functions
Object. toQueryStringGenerates a querystring from key/pair values in an object

Functions

Object. toQueryString

Generates a querystring from key/pair values in an object

Arguments

sourcethe object to generate the querystring from.

Returns

the query string.

Example

Object.toQueryString({apple: "red", lemon: "yellow"}); //returns "apple=red&lemon=yellow"

Element

Custom class to allow all of its methods to be used with any DOM element via the dollar function $.

Summary
Properties
sendSends a form with an ajax post request

Properties

send

Sends a form with an ajax post request

Arguments

optionsoption collection for ajax request.  See Ajax for the options list.

Returns

The Ajax Class Instance

Example

<form id="myForm" action="submit.php">
<input id="email" value="bob@bob.com">
<input id="zipCode" value="90210">
</form>
<script>
$('myForm').send()
</script>
An Ajax class, For all your asynchronous needs.
Generates a querystring from key/pair values in an object
returns the element passed in with all the Element prototypes applied.
Basic XMLHttpRequest Wrapper.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi