0

我有一个表单,想在提交时将其内容提交到服务器。我在这里发现了一个类似的问题1,它建议使用 POST 请求,但我不知道该怎么做。这是我的代码客户端:

<form method='post' action='http://localhost:8080' >
  <textarea id='chatHistory'></textarea>
  <br/><br/>
  <div class="demo">
   <div class="ui-widget"> 
    <input id="tags" size="50" type="text" />
    <input type="submit" value="Send" style="height:40px;width:120px;font-size:18px;" />
   </div>
  </div>
 </form>     

服务器端:

app.post('/', function(req,res)
{
  // create reusable transport method (opens pool of SMTP connections)
  var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "gmail",
    auth: {
      user: "my_mail_id@gmail.com",
      pass: "password"
    }
});

// setup e-mail data with unicode symbols
var mailOptions = {
 from: "Suggestion Box ✔ <my_mail_id@gmail.com>", // sender address
 to: "receiever@gmail.com", // list of receivers
 subject: "Hello ✔&quot;,
 text: req.chatHistory.value
};
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
 if(error){
     console.log(error);
 }else{
     console.log("Message sent: " + response.message);
 }
});
});

邮件正文没有填满来自客户端的值。我认为问题出在:req.chatHistory.value

如何在服务器端获取 chatHistory 值?

4

1 回答 1

1

问题是你从不打电话req.param("myparam");

尝试:

var chatText = req.param("chatHistory"); 

然后,将其传递给邮件函数:

text: chatText

ps:

<textarea id='chatHistory' name='chatHistory'></textarea>  //add name param

与:

<input id="tags" size="50" type="text" name='tags' />   //add name param
于 2013-05-26T17:51:53.480 回答