在处理来自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
}
}
});发布于 2012-07-20 11:01:53
从你的错误来看,看起来this question和that question是相似的。"jQuery_172blah未被调用“错误指的是jsonp回调(由于在其他地方解析失败而未被调用)。我建议..。
crossDomain: true,然后还将传递data的dataType:text或dataType:text json.jsonp:false和jsonpCallback。查看这些文件上的documentation。例如:
var jsonString = JSON.stringify({
recipientemail: email
});
$.ajax({
url: "http://services.ninemsn.com.au/sendtofriend/sendtofriendService.aspx?",
crossDomain: true,
dataType: 'text json',
data: jsonString,
...https://stackoverflow.com/questions/11572012
复制相似问题