This is my AJAX success callback:
success: function(data){
var uD = '<ul class="user-details">';
$.each(data['user details'], (function(key,val){
uD += '<li><label>' + key + ':</label><span>' + val + '</span></li>';
});
uD += '</ul>';
return uD;
}
data is a JSON object.
As you can see, I'm trying to build a list out of the JSON object, but by the time I return the variable uD
, it's undefined. How can I get the value of uD
past the scope of the $.each function?
Edit: Sorry, I should have specified. The return statement was only in the AJAX callback because the AJAX call is within another function (which needs to return something.) Since it's async, I couldn't return 'after' the AJAX call, it had to be in the callback.