我正在开发一个 node.js 应用程序,我正在从我的 app.js 运行 javascript 代码,并且该函数运行正确,所有卡宾枪都通过该函数传递,但我的回调永远不会返回。
脚本运行,一切都与console.log一起出现,但是当我运行带有错误的函数时,回调不是回调:
ReferenceError: Can't find variable: callback
这是代码。
var username;
var password;
function getBalance(username,password,callback) {
console.log("info that main.js received: ",username,password);
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
var spooky = new Spooky({
child: {
transport: 'http',
"ssl-protocol": "any"
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function(err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start('https://bank.simple.com/signin');
spooky.then([{
auth: username+"_"+password
}, function () {
this.evaluate(function (auth) {
var info = auth.split("_");
username = info[0];
password = info[1];
document.getElementById("login_username").value = username;
document.getElementById("login_password").value = password;
}, {
auth:auth
});
}]);
spooky.thenClick('#signin-btn', function() {
this.emit('notifForTitleChange', 'Hello, from ' + this.evaluate(function() {
return document.title;
}));
});
spooky.thenOpen('https://bank.simple.com/account/balances');
spooky.then([{
},function() {
var pre = document.getElementsByTagName("pre")[0];
callback(pre.innerHTML);
}]);
spooky.run();
});
spooky.on('error', function(e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
spooky.on('console', function(line) {
console.log(line);
});
spooky.on('valueChanged', function(greeting) {
console.log(greeting);
});
spooky.on('gotInfo', function(balance) {
console.log(balance);
//Note: this callback isn't getting called :
callback(balance);
});
spooky.on('log', function(log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});
};
module.exports.getBalance = getBalance;