简体   繁体   English

如何传递onComplete包含Ajax类的函数名称的变量

[英]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). Mootools Ajax类具有onComplete参数,您可以通过该参数向其传递函数名称,并且在完成时(明显)它将调用该函数。

http://docs111.mootools.net/Remote/Ajax.js 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. 您的updateFunction变量包含一个字符串。

You need it to hold the function itself, like this: 您需要它来保存函数本身,如下所示:

var updateFunction = this.testFunctionA; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM