Forum: Ruby on Rails Help with onComplete on Ajax.Request

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
917533d6bb5803079146c8bfb16d58b6?d=identicon&s=25 Francis Sinson (franee)
on 2006-12-29 21:41
Hi,

I have a class that has a function that will send an Ajax call to the
server and on the onComplete handler is still on the same class.
Problem is, i can't seem to access the class' variables inside the
method.

Is this possible at all? Because from what i've read, the onComplete
handler should be a global function.  I want it inside the class since i
have to also dynamically adjust the class attributes based on the
response.


Here is a snippet of the class:

CommentProcessor = Class.create();

CommentProcessor.prototype = {

    cell_element: null,
    input_element: null,
    anchor_element: null,
    commentable_type: null,

    submit_input_field: function(){
        var url = '/prototype/add_comment';
        var pars = 'commentable_type=' + this.commentable_type +
'&comment=' +                           this.input_element.value;

    var myAjax = new Ajax.Request(
      url,
      {
        method: 'post',
        parameters: pars,
                        //how do i call the handler function here?
             onComplete: this.handlerFunc(this)
      });

        return false;
    },

    handlerFunc: function(t) {

        this.anchor_element.innerHTML = t.responseText;
   }

};



Thanks,
/franee
This topic is locked and can not be replied to.