I am testing to make an email form with jquery and ajax. The email processes and sends fine but the success function in .ajax does not fire. I am really new to all this functionality so I am unsure what could be wrong. I am so greatful for your help! fyi (#blah) is just an indicator
我正在测试用jquery和ajax制作一个电子邮件表单。电子邮件处理并发送正常,但.ajax中的成功函数不会触发。我对所有这些功能都很陌生,所以我不确定会出现什么问题。我非常感谢你的帮助! fyi(#blah)只是一个指标
$(function() {
$(".button").click(function() {
// validate and process form here
$('#blah').hide();
var name = $("input#name").val();
var email = $("input#email").val();
var phone = $("input#phone").val();
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "http://www.joepolitic.com/contactform.php",
data: dataString,
success: function() {
$('#second').hide();
}
});
return false;
});
});
PHP:
PHP:
<?php
// get posted data into local variables
$EmailFrom = "First Facility Contact Form";
$EmailTo = "xxx@xxx.com";
$Subject = "Contact";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Phone = Trim(stripslashes($_POST['phone']));
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
?>
1 个解决方案
#1
1
Try modifying your code to include the following:
尝试修改代码以包含以下内容:
success: function(result) {
alert(result);
$('#second').hide();
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
}
#1
1
Try modifying your code to include the following:
尝试修改代码以包含以下内容:
success: function(result) {
alert(result);
$('#second').hide();
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
}