For some reason my function is returning undefined while seemingly working in itself.
function getDomains() {
$.ajax({
url: '/rewrites/cgi-bin/ajax.pl?action=listdomains',
dataType:'json',
async: false,
success: function( data ) {
if (data.error) {
alert(data.error);
}
else {
alert(data.domains);
return(data.domains);
}
}
});
}
alert(getDomains());
My first alert shows a populated list but the second is undefined. Does this make any sense?
returnstatement is for thesuccesscallback - you're not returning anything fromgetDomains. You could putvar domains;at the top of your function. Then, in your callback, usedomains = data.domains;, and then putreturn domains;at the end of your function