这是我的代码。如果我从 php 端收到的消息为 0(发生错误),我想阻止提交表单。如果收到的消息是 1 我要提交表单。
$(document).ready(function(){
$('#form').submit(function(e){
register();
});
});
function register(){
$.ajax({
type:"POST",
url:"submit.php",
data: $('#form').serialize(),
dataType: "json",
success: function(msg){
if(parseInt(msg)==1){
window.location=msg;
}
else if(parseInt(msg)==0){
$('#error_out').html(msg);
}
}
});
}
最佳答案
在 register();
之后包含 return false;
关于php - 如何停止使用 Jquery/Ajax 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6654426/