jQuery AJAX not returning false
jQuery AJAX not returning false
如果员工ID存在,我希望下面的程序返回false。如果雇员ID存在,则PHP文件返回true,并将其返回给AJAX函数。
$.post("connect_ajax_php.php",
{type: "checkId", val: val, field: "emp_id", table: "employee"})
.done(function(data, succ){
data = $.trim(data);
if( succ =="success" && data=="true" ){
$( errContId ).html( val+" already exist" );
$( id ).css( {"border":"1px solid red"} );
$('#'+sucImg).html("<img src='images/background/error.png'>");
return false;
}else{
$( errContId ).html("");
$( id ).css( {"border":"1px solid #ccc"} );
$('#'+sucImg).html("<img src='images/background/success.png'>");
}
});
如果您使用ajax调用作为验证步骤,您将在ajax回调中手动提交表单。然后将return false
移动到click处理程序,而不是从ajax响应处理程序调用它。
<form id="myform" action="/url" method="post">
...
<button id="submitbtn" type="submit">Submit</button>
</form>
$("#submitbtn").on("click", function(event) {
$.ajax({
url: "connect_ajax_php.php",
method: "post",
data: {type: "checkId", val: val, field: "emp_id", table: "employee"}
})
.done(function(result) {
if (result == "true") {
// id exists
}
else {
$("#myform").submit();
}
});
return false; // prevent standard form submission
});
相关文章:
- 如果 a 为 false,则 if(a) === if(false)
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 如何将localStorage值设置为false
- JavaScript-切换“;全部检查”;复选框true/false
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- noty.js is returning undefined
- 如何使用javascript将字段强制设置为false
- (false==false==true)怎么可能是真的
- Array.every返回false,而不是类型error
- Javascript If else 只返回 TRUE 或只返回 FALSE
- 为什么当我在数组上测试regex时,它会返回false
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- User getSessionToken() Returning Undefined
- 过滤器返回true或false
- 什么是'true'和'false'和'null'
- 在if语句中,undefined等于false
- 检查文本区域是否为空总是返回false
- Django is_valid() returning false
- JQuery Ajax returning bool(false)
- jQuery AJAX not returning false