Your AJAX request has not finished firing by the time console.log
is being executed.
If you move the console.log
to the success
callback, you will get the data correctly.
var names;
$.ajax({
type : 'POST',
url : postUrl+"/admin/returnUserJSON",
success : function(data){
names = data;
console.log(names);
}
});
I would suggest reading up on asynchronous javascript programming!