denormalizer
denormalizer

Reputation: 2214

How to pass onComplete a variable containing a function name for Ajax class

Mootools Ajax class has a onComplete parameter whereby you can pass a function name to it and it would call that function when it completes (obvious).

http://docs111.mootools.net/Remote/Ajax.js

I want to be able to pass a variable containing the said function instead. How do I go about doing that? My attempt can be seen below.

/*
 * This way works
 */     
var TestClass = new Class({

    myRequest: function()
    {

        $aj = new Ajax(urle, {

          method: 'get',
          update: $('update_div'),
          onComplete: this.testFunctionA

        }).request();

    },

    testFunctionA: function()
    {
        alert('Yo');
    }

});

/*
 * This way doesn't 
 */     
var TestClass = new Class({

    myRequest: function()
    {

        var updateFunction = 'this.testFunctionA'; 

        $aj = new Ajax(urle, {

          method: 'get',
          update: $('update_div'),
          onComplete: updateFunction

        }).request();

    },

    testFunctionA: function()
    {
        alert('Yo');
    }

});

Upvotes: 0

Views: 1357

Answers (1)

SLaks
SLaks

Reputation: 887797

Your updateFunction variable holds a string.

You need it to hold the function itself, like this:

var updateFunction = this.testFunctionA; 

Upvotes: 3

Related Questions