Not sure if it's the best way, but I've used the following to set
parameters...

Object.extend(Ajax.Base.prototype, {
    ajaxBaseSetOptions: Ajax.Base.prototype.setOptions,

    setOptions: function(options){
        this.ajaxBaseSetOptions(options);
        this.options.parameters = this.options.parameters || {};
        this.options.parameters.noCache = new Date().getTime();
        this.options.parameters['_tz_'] = "GMT-" + (new
Date().getTimezoneOffset() / 60)
        this.options.onFailure = this.options.onFailure ||
goToErrorPage;
    }
});

On May 7, 11:34 am, [EMAIL PROTECTED] wrote:
> Hi all.  I am trying to find a way to insert an authenticity_token
> into the params of an Ajax request before it gets sent.
> I've got this much:
>
>   Ajax.Responders.register({
>     onLoading: function(req){
>       if ((req.options.method == 'post') && !
> Object.keys(req.options.parameters).include('authenticity_token')){
> ---->        req.options.parameters.set('authenticity_token',
> rails_gen_token());
>       }
>       alert('method is: ' + req.options.method + '\nparams are: ' +
> Object.keys(req.options.parameters));
>     },
>     onComplete: function(){
>       alert('a request completed');
>     }
>   });
>
> Where you see the arrow is where my problem (obviously) arises.
> rails_gen_token() is a function that correctly returns a valid auth
> token.  What I don't know is 1. How do I actual modify the parameters
> and 2. How can i ensure this happens PRIOR to sending the request?
> onLoading doesn't seem to catch it early enough (and isn't guaranteed
> to anyway).
>
> Any and all help appreciated!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to