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');
}
});
Your updateFunction
variable holds a string.
You need it to hold the function itself, like this:
var updateFunction = this.testFunctionA;
精彩评论