Hi!
I have the following code. The commented lined never get executed and info.response
returns "undefined". Could you help me figure out why it's returning "undefined" and why the commented parts don't get executed, please?
Thank you very much.
app.js:
app.get('/send', function (req, res) {
var mailOptions = {
from: req.query.from,
to: 'chul@stackexchange.com',
subject: 'Applicant',
text: req.query.name + req.query.content
};
console.log(mailOptions);
transport.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
res.end("error");
} else {
console.log("Message sent: " + info.repsonse);
res.end("sent"); // This part does NOT get executed.
};
});
});
index.html:
<script type='text/javascript'>
$(document).ready(function() {
var from, name, content;
$("#send_app").click(function() {
from = $("#from").val();
name = $("#name").val();
content = $("#content").val();
$("message").text("Submitting the application ...");
$.get("http://localhost:3000/send", {
from: from,
name: name,
content: content
}, function(data) {
if (data == "sent") { // This block does NOT get executed
console.log("sent received");
$("#message").empty().html("The e-mail has been sent.");
} else {
console.log(data);
}
});
});
});
</script>