【问题标题】:how to add success message in http post response after button submitted提交按钮后如何在http post响应中添加成功消息
【发布时间】:2018-11-19 18:31:42
【问题描述】:

我正在使用 nodemailer 和 express...

我想在表单是否正在提交时添加文本消息并在前端加载。

.ts

  sendMail(value) {    
    console.log('email sent');    
    // this.form.reset();
    const data = {
        to: 'xxxx@gmail.com',
        subject: this.name,
        txt:  'Email:' + this.email + 
              'Name:' + this.name + 
              'Message:' + this.message
    };
    return this.http.post('http://localhost:3000/api/mail/contact', data).subscribe(      
      data => console.log(data)      
    );
  }

【问题讨论】:

  • subscribe((data)=>{ //success },(error)=>{ //error })
  • 您好,如果我理解正确,您想在处理时显示进度条吗?如果是这样,我建议你看看这个:material.angular.io/components/progress-bar/overview希望它会有所帮助。谢谢,杰里米

标签: javascript express angular5 nodemailer


【解决方案1】:

试试这个:

 sendMail(value) {    
    console.log('email sent');    
    // this.form.reset();
    const data = {
        to: 'xxxx@gmail.com',
        subject: this.name,
        txt:  'Email:' + this.email + 
              'Name:' + this.name + 
              'Message:' + this.message
    };
    return this.http.post('http://localhost:3000/api/mail/contact', data).subscribe(      
      data => {alert(data)},Error => {alert("failed data")}    
    );
  }

您还可以使用 bootstrap 4 警报(或其他):https://www.w3schools.com/bootstrap4/bootstrap_alerts.asp

【讨论】:

  • 数据失败并重复发送电子邮件prntscr.com/jt89wv
  • 或者发送邮件后可能出现故障
  • 它返回错误状态成功你能告诉我你的服务器代码(你返回什么)
  • 这是我的服务器代码 prntscr.com/jth0py 我不知道为什么我有一个错误.. 但是电子邮件已成功发送
猜你喜欢
  • 2021-05-09
  • 1970-01-01
  • 1970-01-01
  • 2018-03-26
  • 2021-03-10
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 1970-01-01
相关资源
最近更新 更多