Ajax

Ajax, set_request_headers

Ajax is used to perform Ajax requests. It mimics the Prototype library's Ajax functionality.

Example

new Ajax('javascriptmvc/todos', 
    {parameters: 
        {todo: {description: 'take out trash'} }
    }
)

Class Methods

Ajax

new Ajax(url[, options]) -> XMLHttpRequest

Initiates and processes an AJAX request.

options

OptionDefaultDescription
asynchronous true Determines whether XMLHttpRequest is used asynchronously or not.
contentType 'application/x-www-form-urlencoded' The Content-Type header for your request. You might want to send XML instead of the regular URL-encoded format, in which case you would have to change this.
method 'post' The HTTP method to use for the request. The other widespread possibility is 'get'.
parameters '' The parameters for the request, which will be encoded into the URL for a 'get' method, or into the request body for the other methods. This can be provided either as a URL-encoded string or as any Hash-compatible object (basically anything), with properties representing parameters.
requestHeaders See text Request headers are passed as an object, with properties representing headers.
cache true true to cache template.

Option callbacks

Callbacks are called at various points in the life-cycle of a request, and always feature the same list of arguments. They are passed to requesters right along with their other options.

CallbackDescription
onComplete Triggered at the very end of a request's life-cycle, once the request completed, status-specific callbacks were called, and possible automatic behaviors were processed.

Prototype Methods

set_request_headers

request.set_request_headers()

This function is used by Ajax to set the transport's request headers if possible.