Ajax.js

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

Dependencies

Moo.js, Function.js, Array.js, String.js, Element.js

Author

Valerio Proietti, http://mad4milk.net

License

MIT-style license.

Summary
Ajax.js Contains the ajax class.
Ajax For all your asynchronous needs.
Properties
request Executes the ajax request.
evalScripts Executes scripts in the response text
Object related Functions
Functions
Object. toQuerySTring Generates a querysting from a key/pair values in an object
Element Custom class to allow all of its methods to be used with any DOM element via the dollar function $.
Properties
send Sends a form with an ajax post request
toQueryString Reads the children inputs of the Element and generates a query string, based on their values.

Ajax

For all your asynchronous needs.  Note: this class implements Chain

Arguments

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

Options

method ’post’ or ‘get’ - the prototcol for the request; optional, defaults to ‘post’.
postBody if method is post, you can write parameters here.  Can be a querystring, an object or a Form element.
async boolean: asynchronous option; true uses asynchronous requests.  Defaults to true.
onComplete function to execute when the ajax request completes.
onStateChange function to execute when the state of the XMLHttpRequest changes.
update $(element) to insert the response text of the XHR into, upon completion of the request.
evalScripts boolean; default is false.  Execute scripts in the response text onComplete.

Example

var myAjax = new Ajax(url, {method: 'get'}).request();
Summary
Properties
request Executes the ajax request.
evalScripts Executes scripts in the response text

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

Object related Functions

Summary
Functions
Object. toQuerySTring Generates a querysting from a key/pair values in an object

Functions

Object. toQuerySTring

Generates a querysting from a key/pair values in an object

Arguments

source the 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
send Sends a form with an ajax post request
toQueryString Reads the children inputs of the Element and generates a query string, based on their values.

Properties

send

Sends a form with an ajax post request

Arguments

options option collection for ajax request.  See <Ajax.initialize> for option list.

Returns

The Ajax Class Instance

Example

<form id="myForm" action="submit.php">
<input name="email" value="bob@bob.com">
<input name="zipCode" value="90210">
</form>
<script>
$('myForm').send()
</script>

toQueryString

Reads the children inputs of the Element and generates a query string, based on their values.  Used internally in Ajax

Example

<form id="myForm" action="submit.php">
<input name="email" value="bob@bob.com">
<input name="zipCode" value="90210">
</form>

<script>
$('myForm').toQueryString()
</script>

Returns

email=b.nosp@m.ob@bob.nosp@m..com&zipCode=90210

function $( el )
returns the element passed in with all the Element prototypes applied.
My Object Oriented javascript.
Contains Function prototypes, utility functions and Chain.
function $A( array )
Copy the array and returns it.
Same as Array.copy, but as function.
Contains Array prototypes and the function $A;
Contains String prototypes and Number prototypes.
Contains useful Element prototypes, to be used with the dollar function $.
For all your asynchronous needs.