So I was looking how to validate before AJAX executes. My AJAX was works fine before I add if ($("#ModalsForm").validate()){}. After I add that validate, it will validate and return true and send Get to my index.php.
index.php?bookingid=10040917035610&roomid=10&...
My HTML
<form id="ModalsForm" method="post" data-parsley-excluded="[disabled=disabled]">
<div id="myModal" class="modal fade"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display:none;">
<div class="modal-dialog modal-lg">
<div class="modal-content" id="modalcontent">
<!-- AJAX onclick content modal -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</form>
My AJAX
function ConfirmSubmit() {
var x = confirm("Are you sure you want to save or update?");
if (x) {
if ($("#ModalsForm").validate()) {
e.preventDefault();
$.ajax({
type: "POST",
url: "modules/BookingCalendar/runsave.php",
data: $("#ModalsForm").serialize(),
contentType: "application/x-www-form-urlencoded",
success: function(result) {
alert(result);
//$("#information").html(result);
$('#myModal').modal('toggle');
}
});
return false;
} else {
return false;
}
} else {
return false;
}
}
Did I miss something when I validate my form?
<script>
$('#ModalsForm').validate({
submitHandler: function() {
if (confirm("Are you sure you want to save or update?")) {
$.ajax({
type: "POST",
url: "modules/BookingCalendar/runsave.php",
data: $("#ModalsForm").serialize(),
contentType: "application/x-www-form-urlencoded",
success: function (result) {
alert(result);
$('#myModal').modal('toggle');
}
});
return false;
}
}
});
</script>
Newest From Rory McCrossan, it's caught error in console
e.preventDefault():eis not defined anywhere. Did you check the console for errors?