0
回調的$就工作在Firefox 4.0.1和IE9
不工作我使用jQuery的此功能,電子郵件聯繫。以下是代碼。
控制器運行正常,表明javascript正在運行! 只有$ .ajax事件顯然沒有被調用。
的Javascript
$(window).ready(function() {
//Send mail
$("div.contato-pedidooracao form").submit(function() {
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "Contato/SendMail",
data: dataString,
dataType: "json",
beforeSend: function() { //Dont Work in IE9 and Firefox!!
$(".sending").show();
$(".status").show();
$(".status > span").show();
$(".submit > input").attr('disabled', true);
},
complete: function() { //Dont Work in IE9 and Firefox!!
$(".sending").hide();
$(".message").show();
$(".status > span").hide();
$(".submit > input").removeAttr('disabled');
},
success: function (data) { //Dont Work in IE9 and Firefox!!
$(".message").empty();
$(".message").append("<p>Mensagem enviada com sucesso!</p>");
},
error: function() { //Dont Work in IE9 and Firefox!!
$(".message").empty();
$(".message").append("<p>Ocorreu um erro ao tentar enviar a mensagem.</p>");
}
});
});
});
控制器
[HttpPost]
public JsonResult SendMail(string name, string phone, string cel, string email, string message)
{
using (var mail = new MailMessage())
{
mail.To.Add("--email--");
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 sucesso!" });
}
HTML
<div class="content contato-pedidooracao">
@using (Html.BeginForm())
{
<p>Conte-nos seu pedido</p>
<div class="inline">
@Html.Label("name", "Nome:")
@Html.TextBox("name", "")
</div>
<div class="inline">
@Html.Label("phone", "Telefone:")
@Html.TextBox("phone", "", new { @class = "phone" })
@Html.TextBox("cel", "", new { @class = "phone" })
</div>
<div class="inline">
@Html.Label("email", "e-mail:")
@Html.TextBox("email", "", new { @class = "email" })
</div>
<div class="inline">
@Html.Label("message", "Mensagem:")
@Html.TextArea("message", "")
</div>
<div class="status">
<span>Enviando mensagem:</span><img class="sending" src="@Href("~/Images/ajax-loader2.gif")" alt="Enviando..." />
<div class="message"></div>
</div>
<div class="submit">
<input type="submit" value="Enviar" title="Enviar" />
</div>
}
</div>