I have the following JavaScript code (and jQuery):
function checkEmail(email) { if (email.length) { $.getJSON('ajax/validate', {email: email}, function(data){ if (data == false) {
I want the anonymous function to be return data for the parent function, checkEmail() . I tried to do something like this:
function checkEmail(email) { if (email.length) { var ret = null; $.getJSON('ajax/validate', {email: email}, function(data){ if (data == false) {
But of course, this will not work, because the call to $.getJSON() is asynchronous, so it will return ret until the GET request completes.
Any thoughts here?
Thanks!
javascript jquery ajax
frontendbeauty
source share