1
The ajax request, returns me "1" or "0". Every time I click the next button, but it is not blocking the commit. As I should do to validate the values, if I have a "0" answer, it should lock the commit 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();
});
Good night , bicho instead of putting Return jsonData , there inside the Ajax Success , try to validate in that location, before using retur jsonData , do the check and only after the return, if it is 0 False , if true you return jsonData , see if this helps you .
– Ricardo Lucas
Good evening, before returning to JSON, validate. If it is
0
,return false;
– diegofcruz
How could you do that, post an answer so I can view your solution.
– Ivan Ferrer
Give me more information on your JSON of return of the Success function inside your ajax, so I can publish an appropriate response to your problem.
– Ricardo Lucas
nor is it a JSON is just "1" and "0", nothing more... In the.log (jsonData) console, it returns me "1" or "0". Only that it is not returning true or false, at the click of the button, even making the request ajax.
– Ivan Ferrer