Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simplified ajax requesst with class inheritable options.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.rdoc

AjaxParty

Simplified Prototype Ajax Requests with class inheritable options.

Example

Syntax

new Ajax.Party.Post(url, parameters, onSuccessCallback, options)

Any Prototype Ajax Options can be passed as options.

A standard form submission request looks like this:

new Ajax.Party.Post($('form').action, $('form').serialize(true), onSuccessCallback)

Or you can pass the parameters function as an argument.

new Ajax.Party.Post('/', someFunctionThatReturnsAnObject, onSuccessCallback)

Have something you need to add to all requests? Maybe the session id or rails autenticity token? Just include it in the default options.

Ajax.Party.class_default_options = {
  parameters: {
    'session_id': 'id'
  }
}

Maybe you only want to set the options for post requests?

Ajax.Party.Post.class_default_options = {
  parameters: {
    'authenticity_token': 'some_token'
  }
}

Every request that uses Ajax.Party.Post or one of it's subclasses will have authenticity_token.

You can create your own subclasses to further refine options. You can specify default instance and class options.

// Ajax.Party.create(class_name, default_instance_options, default_class_options)
Ajax.Party.create('FormPost', {}, { method: 'post', onSuccess: StandardForm.callback })
new Ajax.Party.FormPost($('form').action)

Or we could subclass Ajax.Party.Post and skip the method option!

Ajax.Party.Post.create('FormPost', {}, { onSuccess: StandardForm.callback })
new Ajax.Party.Post.FormPost($('form').action, $('form').serialize(true))

Or we could set set the class default option parameters as a function.

Ajax.Party.Post.create('FormPost', {}, { 
  parameters: function() { $('form').serialize(true) }, 
  onSuccess: StandardForm.callback 
})
new Ajax.Party.Post.FormPost($('form').action)

Or you can go even further by continuing the subclass craziness.

Ajax.Party.Post.FormPost.create('SpecialForm', {} { parameters: { special_parameter } })
new Ajax.Party.Post.FormPost.SpecialForm($('form').action)

Subclasses of AjaxParty will inherit all options of its superclasses.

Ajax.Party.class_default_options = {
  parameters: {
    'authenticity_token': 'some_token'
  }
}

Ajax.Party.Post.class_default_options = {
  evalJSON: true
}

Ajax.Party.Post.FromPost will automaticly have the authenticity token and evalJSON parameters as will any subclasses of it. The subclass options always take precedence over the superclass options, class options take precedence over instance default options and options passed to the method take precedence over all.

Coming Soon

Better Documentation Ajax.Party.AutoComplete Testing in something other than Firefox 3

TODO

Get the tests under control.

Homepage

github.com/kristopher/ajaxparty

License

Copyright © 2008 Kristopher Chambers <maito:kristopher.chambers@gmail.com> and Elijah Miller <elijah.miller@gmail.com>, released under the MIT license

Something went wrong with that request. Please try again.