我已经编写了通过 ajax 发送电子邮件的代码。单击按钮后,电子邮件已成功发送,但我没有收到警报消息,这是为什么,我的代码中有什么问题,请帮助我找出错误。
这是我的 Ajax 代码
<script>
$(function () {
$("#myForm").submit(function (evenr) {
event.preventDefault(e);
var form_data = $(this).serialize();
$.ajax({
url:'mail.php',
method:'POST',
data:{data},
success:function(data){
alert(data);
$("#success_message").attr("style", "display: none");
}
});
});
});
</script>
这是我的 html 表单
<div class="col-lg-5 col-md-6 home-about-left">
<form class="form-area contact-form text-right" id="myForm">
<h4 style="text-align: left;color: #ffffff;font-size: 24px;">Get a free consultation</h4></br>
<div class="row">
<div class="col-lg-12 form-group">
<div class="alert alert-success" id="success" style="display: none;">
<strong>Success!</strong> Indicates a successful or positive action.
</div>
</div>
<div class="col-lg-12 form-group">
<input name="name" placeholder="Name" id="formClass" class="common-input mb-20 form-control" required="" type="text">
<input name="phone" placeholder="Phone Number" id="formClass" class="common-input mb-20 form-control" required="" type="text">
<input name="email" placeholder="Email" id="formClass" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$" class="common-input mb-20 form-control" required="" type="email">
<input name="service" placeholder="Type of Pest control services" id="formClass" class="common-input mb-20 form-control" required="" type="text">
</div>
<div class="col-lg-12">
<!--<button class="genric-btn primary" style="float: left;">Send Message</button>-->
<input name="submit" type="submit" class="genric-btn primary" style="float: left;" value="Send Message">
</div>
</div>
</form>
</div>
SMILET
沧海一幻觉