我在处理来自 AJAX 的表单时遇到了一个奇怪的问题。
它按预期工作,但由于某种原因它会触发错误而不是成功。
这是代码:
$(".sendBtn").click(function(e) {
campaigncode = "#####";
senderemail = "test@email.com";
subject = "Test";
sendermessage = "Test";
targetURL = "www.abc.com";
email = $(".email").val();
//Email Validation
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if( email ==""){//Empty Check
alert('Please enter your email');
e.preventDefault();
} else {
if(!emailReg.test( email )) {//Email validation
alert('*Please enter valid email');
e.preventDefault();
} else {
//Ajax Start
$.ajax({
url: "http://services.ninemsn.com.au/sendtofriend/sendtofriendService.aspx?showdefaultmessage=true",
context: document.body,
type: "POST",
data: {campaigncode:campaigncode, recipientemail:email, senderemail:senderemail, subject:subject, sendermessage:sendermessage, targetURL:targetURL},
dataType: "jsonp",
success: function() {
alert('Success');
},
error: function() {
alert('Error');
}
});//Ajax End
}
}
});