I want to use AJAX to determine if form values ββare acceptable to me (this is not form validation). AJAX result will determine if a form is submitted or not.
Below you will see that I am making an AJAX call when the form is submitted, and depending on what is being returned (either empty, which is acceptable, or an error message that is not acceptable), I would like to return true; or return false; $("form").submit .
I suspect my problem is being in AJAX success: Please help me get the result from an AJAX call so that I can do something like if (result == "") { return true; } else { return false; } if (result == "") { return true; } else { return false; } if (result == "") { return true; } else { return false; } .
WORKERS:
$("form").submit(function(e) { e.preventDefault(); var form = this; var tray = $('select[name=tray_id]').val(); $.ajax({ type: "POST", url: "modules/reserve-check.php", data: {tray_id: tray}, cache: false }).done(function(result) { if (result == "") form.submit(); else alert(result); }).fail(function() { alert('ERROR'); }); });
ORIGINAL:
$("form").submit(function() { var tray = $('select[name=tray_id]').val(); $.ajax({ type: "POST", url: "modules/reserve-check.php", data: {tray_id: tray}, cache: false, success: function(result) { alert(result); }, error: function(result) { alert(result);
source share