Let me paint you a picture: I'm currently in the process of validating a form that contains 4 input boxes. As part of this validation, two checks are being carried out. One check verifies if three boxes contain some values (handled by Parsley), while another box needs to have its code sent to the server for a verification process. Here's how I'm tackling this challenge:
(pseudo code)
onFormSubmit(){
var isValid,
// Handling the asynchronous response from an AJAX call
validateCode = function(response){
isValid = response; // true or false
};
// Using Parsley to perform form validation
isValid = $('#form').parsley('validate');
// Triggering an external file function for AJAX result, with 'validateCode' as the callback function
this.emit('validateCode', {value: promoCodeValue, validate: validateCode});
// The issue arises when trying to update the value of 'isValid' after the AJAX call
doOtherStuff(isValid)
}
My query now is about finding a solution that allows me to wait for the completion of the AJAX request before proceeding with the execution of the 'doOtherStuff' function. Any suggestions on how to achieve this?