当创建一个jQuery函数来提交表单时,我需要在发送请求之前先做一个验证。下面是我的代码:
$('#Form').submit(function(e){
e.preventDefault();
e.stopImmediatePropagation();
var PhotoID = $('#PhotoID').val();
// I will set the PhotoID to 0 just for testing.
var PhotoID = '0';
if (PhotoID == '0') {
$('#GlobalError').removeClass('hidden');
} else {
return true;
$.ajax({
type: "POST",
url: $(this).attr( 'action' ),
data: $(this).serialize(),
beforeSend: function(){
$("#loader").fadeIn(2000);
},
success: function( response ) {
}
});
}
});当PhotoID不同于0时,我想提交表单并遵循正常的页面更改为表单操作属性。我知道e.preventDefault()的对立面是return true;,但它不工作。该函数正在被正确触发。所以问题只是关于表单提交的处理。
https://stackoverflow.com/questions/41346230
复制相似问题