[英]AJAX POST success and error firing
我在这里检查了许多关于同一问题的帖子,但没有任何效果,或多或少地表现为故障:
function onbtnclick(){
var user_email=$('#user_email').val();
var send_data = {email:user_email};
$.ajax({
type: 'POST',
url: 'someURL.php',
crossDomain: true,
data:send_data,
dataType: 'text',
success: function(responseData, textStatus, jqXHR) {
alert("Thank you for the mailing list");
},
error: function (responseData, textStatus, errorThrown) {
alert('Your email is already in our mailing list.');
console.log('log e:'+responseData);
console.log('log e:'+textStatus);
console.log('log e:'+errorThrown);
}
});
return false;
}
};
<form name="myform">
<input id="user_email" type="email" name="email" placeholder="Your Email Here" style="width:300px" required><br>
<br><button type="submit" class="leka-button button-style2 offer_button" onclick="onbtnclick()"><h5>SIGN UP</h5></button>
</form>
只是我试图警告正确的消息,如果新用户触发成功或如果他注册要触发错误,我试图删除dataType:'text'或添加'json'和\\,同时也删除了crossDomain属性,但是所有操作都没有不给我原因。 如果这很有用,请在此处触发AJAX脚本。
单击提交按钮时,将调用JavaScript。
JavaScript运行。 Ajax请求已准备就绪。 JavaScript完成。 提交按钮的默认行为将提交表单。 页面卸载。 Ajax请求被取消 。 定期提交表单。
摆脱onclick
属性。 而是将事件处理程序与JavaScript绑定。
$(function () {
var $form = $([name="myform"]); // `name` is obsolete for form elements, give it an ID instead
$form.on('submit', onbtnclick);
function onbtnclick(event) { // Give this function a better name
event.preventDefault(); // Don't submit the form normally
// Then put the rest of your existing code
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.