开发者

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

开发者 https://www.devze.com 2023-01-24 02:23 出处:网络
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).

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');
    }

});


Your updateFunction variable holds a string.

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

var updateFunction = this.testFunctionA; 
0

精彩评论

暂无评论...
验证码 换一张
取 消