Based on some JSON I recieve from an ajax request, I wish to either allow or deny a submit button press (return true/false).
I've attempted to implement a promise, however, I can still see 'product unavailable' is called before I recieve my ajax response.
Is the issue down to it being a form/submit button? Or is this still possible?
var oAH = {
ValidateSubmit : function(self){
// send request to handler
$.ajax({
type: "POST",
url: "",
data: aData,
cache: false})
.done(function(data) {
var oJSON = JSON.parse(data);
if(oJSON.Status === 1){
// return true to allow form to submit
return true;
}else{
console.log('product unavailable (error message)');
return false;
}
})
}
}
// click handler
$('#submitButton').on('click', function(){
return oAH.ValidateSubmit(this);
}