Your problem is related to defective functions .
your success function in:
$.ajax({ url: 'ajax.php', type:'POST', data: data_string, dataType: 'json', cache: false, async: false, success: function(response){ callback(response); } });
Excluded. Think of it as a thread. So submit continues without waiting for the callback to complete. That way, it does not call event.preventDefault() or, more accurately, it does it, but too late, submit is already returned.
I would change what it would ever call from the submit button (which I assume is currently) to a regular button, then confirm it, and then submit the form if this check was successful using $('form').submit(); .
$('#button').click(function(event) { var xxx = $('#xxx').val(); var yyy = $('#yyy').val(); var zzz = $('#zzz').val(); var uuu = $('#uuu').val(); if (zzz != '000000' && zzz != '') { validate_xxxyyy(uuu, function(response) { if (response === false) { if (xxx == '') { alert("XXX undefined!"); } else if (yyy == '') { alert("yyy Undefined!"); } } else { $('#form1').submit(); } }); } else { $('#form1').submit(); } }); function validate_xxxyyy(uuu, callback) { var data_string = 'uuu=' + uuu; $.ajax({ url: 'ajax.php', type:'POST', data: data_string, dataType: 'json', cache: false, async: false, success: function(response){ callback(response); } }); }
source share