我正在尝试通过SendGrid + Parse云代码模块的表单发送电子邮件。一切都在功能上很好,电子邮件正在通过。但是,当我查看我的日志时,我得到以下内容:
Result: ReferenceError: response is not defined
//卖弄.就是
var express = require('express');
var sendgrid = require('sendgrid');
sendgrid.initialize("USER", "PASS");
var app = express();
// App configuration section
app.use(express.bodyParser()); // Middleware for reading request body
app.post('/email', function(req, res) {
var name = req.body.name;
var email = req.body.email;
var message = req.body.message;
sendgrid.sendEmail({
to: '[email protected]',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
response
没有定义,我想你打算写
sendgrid.sendEmail({
to: '[email protected]',
from: email,
subject: 'Message from ' + name + ' via Web',
text: message
}, {
success: function(httpResponse) {
console.log(httpResponse);
httpResponse.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
httpResponse.error("Uh oh, something went wrong");
}
});
顺便说一句:你应该总是通过“use strict”设置严格模式 - 这样可以更快地捕获未定义的变量。