The ajax request, returns me "1" or "0". Every time I click the forward button, however, it is not blocking the submission. How do I validate the values, if I have a "0" answer, it should block the submission method:
DDWFrontEnd = function() {
self.checkUsedTimeSlot = function() {
var ddw_order_date = self.$ddw_order_date.val();
var retorno = false;
if (self.timeSlotId != null) {
var promise = $.ajax({
type: 'POST',
url: 'ajax.php?rand=' + new Date().getTime(),
async: false,
cache: false,
data : {
ddw_order_date: ddw_order_date,
id_timeslot: self.timeSlotId
},
dataType : "json",
complete: function(d) {
},
success: function(jsonData) {
return jsonData;
},
});
return promise;
}
}
$('input.avancar').bind('click', function(e) {
var bool = self.checkUsedTimeSlot().then(
function(returnBool) {
return (returnBool == '1');
});
if (!bool) {
e.preventDefault();
return false;
}
return true;
});
}
$(function() {
ddw = new DDWFrontEnd();
});