AJAX POST成功并错误触发
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
}
});
相关文章:
- 错误405:向Java控制器(Ajax)发送JSON时找不到POST方法
- jQuery在输入下验证post错误消息
- 使用javascript ajax post方法的未定义偏移PHP错误
- DreamFactory REST API POST休息/用户/会话请求总是在IE9中返回错误
- jQuery AJAX Post方法错误(语法错误)
- 为什么我的$http.post返回一个400错误
- AngularJS$http.post调用返回502(坏网关)错误
- angularjs post方法中得到405错误
- POST encodeURI查询字符串内部服务器错误 500
- AJAX POST成功并错误触发
- $.post返回语法错误,意外''
- Jquery AJAX Post:500(内部服务器错误)
- angularjs中的POST 400错误请求
- javascript中的POST错误
- AJAX Http POST:没有传输错误
- jQuery ajax POST在chrome中返回错误
- 带有jQuery的Ajax POST抛出空错误
- $.ajax vs $.post:获取允许源错误
- 无法运行内部功能测试.错误:[POST http://localhost:4444/wd/hub/session] co
- 未捕获的类型错误:$.post不是函数