我想提交一個表單數據使用jQuery的PHP。我不想在默認情況下提交它。代碼工作正常。我不知道在哪裏使用event.preventDefault();
在哪裏使用preventDefault();在jquery中停止提交表單數據
下面是我的jQuery代碼
<script>
$(function() {
$("#submit").click(function() {
var password = $("#password").val();
var confirmPassword = $("#confirm_password").val();
var dataString='password='+ password + 'confirmPassword='+ confirmPassword;
if (password != confirmPassword) {
alert("Passwords and Confirm Password Should match.");
return false;
}
else{
$.ajax({
type: "POST",
url: "update-password.php",
data: dataString,
success: function(result){
alert(result)
}
});
}
});
});
</script>
注意:不要使用'click'事件來控制表單提交。它被鍵盤表單提交繞過!始終使用'submit'事件。 –
@TrueBlueAussie,然後發佈一個答案。 – Luke