I am a java/jquery novice and struggling with the following:
$(document).ready(function() {
//Prevent SUBMIT if Session setting = On (Ajax)
$('#formID').submit(function(e) {
var prevent = false;
$.ajax({
type: "POST",
url: "url/to/ajax_file.php",
cache: false,
success: function(res){
if(res == "On") { alert('Session is ON so submit should be prevented'); prevent = true; }
}
});
if (stop2) { e.preventDefault(); }
});
});
The session setting is returned ok, and the alert is presented. But I also want to prevented the form submit if the session setting returned = 'On'. This is not happening. There is obviously something I do not understand, any advice?