gpt4 book ai didi

javascript - Meteor/Javascript 函数错误 - TypeError : callback is not a function

转载 作者:行者123 更新时间:2023-12-02 13:51:45 25 4
gpt4 key购买 nike

我一直在查看其他 Stack Overflow 问题,但仍然无法弄清楚我的问题。我在浏览器控制台中收到此错误:

Exception in delivering result of invoking 'formMethod1': TypeError: callback is not a function

我已将代码放在下面,并在错误引用的行上添加了注释。看起来“err”对象没有被传递,但实际上正在调用回调并且整个过程都在进行,它只是永远不会捕获错误。

submitForm1(entry,
processForm1(err,res,entry,function(err,res){
//Done processing
console.log(err); //Doesn't work
console.log(res); //Doesn't work
console.log("Done"); //Works
})
)

function submitForm1(entry, callback) {

Meteor.call('formMethod1', {
params: {
user: Meteor.user().username,
activity: entry
}
}, function(err,res){
if(err){
console.log(err) //Works
callback(err, res, entry) //This is where the error happens
} else{
callback(undefined, res, entry)
}
}
);
}

function processForm1(err, res, entry, callback) {
console.log(err); //Doesn't work
console.log(res); //Works
console.log(entry); //Works
if (err) {
if (err.error == "1001") { //Activity not found
//Handle Error
callback("Activity Not Found");
} else {
//Handle Error
callback(err.message);
}
} else { //No Errors
callback(undefined,"Submitted");
}
}

编辑:你们都让我朝着正确的方向前进。这是更正后的代码:

submitForm1(entry, function(err,res){
processForm1(err,res,entry,function(err,res){
//Done processing
console.log(err);
console.log(res);
console.log("Done");
})
});

最佳答案

您正在调用作为回调传递的函数,而不是...传递它,然后将另一个函数作为参数传递给that。我认为您以错误的方式将相同功能的两种口味混合在一起。像这样修复:

submitForm1(entry,
function (err,res,entry) {
//Done processing
console.log(err);
console.log(res);
console.log("Done");
}
)

关于javascript - Meteor/Javascript 函数错误 - TypeError : callback is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40984016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com