Help with onComplete on Ajax.Request


#1

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