I need to save the variable from the ajax request after it finishes, but unfortunately it returns undefined
. The validate()
method is used in a HTML form to validate the user supplied input, so the method will need to return a true/false value.
function validate () {
var returnResponse;
ajax_validate().done(function (response) {
if (response.toString() == "true") {
alert('Proceed');
}
else {
alert('Error');
}
returnResponse=response;
});
return returnResponse;
}
function ajax_validate () {
var data = {
'action': 'my_action',
'request': document.getElementById("ID").value
};
return jQuery.post(ajax_object.ajax_url, data);
}