【发布时间】:2011-06-17 23:23:59
【问题描述】:
我有一个发送电子邮件的功能。 此功能正常工作,但总是触发错误功能,没有发生任何错误(我正在接收电子邮件)。
关注我的 Javascript:
//Send mail
$("div.contato-pedidooracao form").submit(function () {
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "Contato/SendMail",
data: dataString,
dataType : "json",
success: function (data) { alert("OK"); },
error: function (data) { alert("Error"); }
});
});
控制器
[HttpPost]
public ActionResult SendMail(string name, string phone, string cel, string email, string message)
{
try
{
using (var mail = new MailMessage())
{
mail.To.Add("--mailhere--");
mail.From = new MailAddress("\"" + name + "\" <" + email + ">" );
mail.Subject = "Pedido de Oração - " + name;
mail.Body = message;
mail.IsBodyHtml = false;
new SmtpClient().Send(mail);
}
return Json(new{Sucess = true, Message = "Email enviado com sucess!" } );
}
catch (Exception ex)
{
return Json(new{Sucess = false, Message = ex.Message } );
}
}
【问题讨论】:
标签: jquery ajax json post http-post