sendForm: *function*() {
*// let''s serialize the content of the form*
*// and send it to the server
** var* sendFormCompletedFn = this.sendFormCompleted.bind(this);
*var* myAjax = *new* Ajax.Request(this.form_action, {
parameters: Form.serialize(
this.edit_form),
onComplete: sendFormCompletedFn});
},
This will enable access to "this" in sendFormCompleted
Enjoy,
Amol Katdare
On 12/13/05, Tarek Ziadé
<ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hello,
>
> I have a small class where i want to use attributes of the instance when
> an ajax call returns, so I wrote:
>
> *var* MyClass = Class.create();
>
> MyClass.prototype = {
> initialize: *function*(form_id, rendered_id) {
> this
> .form_id = form_id;
>
> *var* edit_form = $(form_id);
> *var* rendered_node = $(rendered_id);
>
> *if* (!edit_form || !rendered_node) {
>
> this.enabled = *false*;
> }
> *else* {
> *// getting the action value*
> this.form_action = edit_form.action;
> this.edit_form = edit_form;
>
> this.rendered_node = rendered_node;
> this.enabled = *true*;
> }
> },
>
> sendForm: *function*() {
>
> *// let''s serialize the content of the form*
> *// and send it to the server*
> *var* myAjax = *new* Ajax.Request(this.form_action, {
> parameters: Form.serialize(
> this.edit_form),
> onComplete: this.sendFormCompleted});
> },
>
> sendFormCompleted: *function*(originalRequest) {
> *var* result = originalRequest.responseText
> ;
> *// we need to replace the form with the result*
> *// XXX How to get this here ??*
> this.rendered_node.innerHTML = originalRequest.responseText;
> }
> }
>
>
> The problem I have is that in sendFormCompleted, wich is called by the
> transport,
> I do not have access to "this".
>
> So my question is: what would be the simplest way to achieve this, do i
> have to subclass Ajax.Request ?
>
> Regards
>
> Tarek
>
> --
> Tarek Ziadé | www.afpy.org
> Python - why settle for snake oil when you can have the whole snake?
> (Mark Jackson)
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
>
>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs