2013-05-26 137 views
2

我为node.js使用sendgrid库。目前有一个回调,它被炒了两次。Node.js回调调用两次

@invite = (email, agencyId, callback) -> 
    (app.get 'agencies').findOne {_id: agencyId}, {name:1}, (error, agency) -> 
    sendgrid.send { 
     to: email, 
     from: '[email protected]', 
     subject: "You have been invited to #{agency.name}", 
     html: "<html><body>Have fun</a></body></html>" 
    }, (success, message) -> 
     console.log arguments 
     if success 
     console.log callback 
     callback() 
     else 
     console.log message 

这是我从控制台

{ '0': true, '1': undefined } 
[Function] 
{ '0': false, '1': 'Invalid JSON response from server' } 
Invalid JSON response from server 

的事情是搞定了,我从1路调用函数和它的作品完美的罚款。如果我从另一个单独的路由调用它,它会触发回调,但它表示回调变量(函数)未定义。

任何线索?

回答

0

我建议你将参数记录到@invite函数。我怀疑这会被调用两次,一次是正确的参数,一次是由于程序中其他地方的错误导致错误的参数。

+0

我有几次......它只被调用一次。 – elbuo