I am just really stuck when it comes to returning a function inside another function then inside another function. All I want it to do is send a user Id to getUser then return to postFeed or put it in authorOfPost. So I can put it in a p tag.
function postFeed(a){
$('.loginForm').remove();
for(i=0;i<a.data.length;i++){
getUser(a.data[i].user.id);
console.log(authorOfPost);
if ((a.data[i].hasOwnProperty("title") && a.data[i].hasOwnProperty("text"))&&(a.data[i].title !="" && a.data[i].text !=""))
{
$('.body').append('<div class="post" ><h4 class="date-title">'+ a.data[i].display_time +'</h4><h1 class="title">'+ a.data[i].title + '</h1><p class="content">'+ a.data[i].text+'</p><p class="author">'+authorOfPost+'</p></div>' );
}
else if (a.data[i].hasOwnProperty("title")&& a.data[i].title !="") {
$('.body').append('<div class="post"><h4 class="date-title">'+ a.data[i].display_time+'</h4><p class="content">'+ a.data[i].title+'</p><p class="author">'+authorOfPost+'</p></div>' );
}
else if (a.data[i].hasOwnProperty("text") && a.data[i].text !="") {
$('.body').append('<div class="post"><h4 class="date-title">'+ a.data[i].display_time+'</h4><p class="content">'+ a.data[i].text+'</p><p class="author">'+authorOfPost+'</p></div>' );
}//end of else if
}//end of forloop
}//end of postFeed
var authorOfPost="";
function getUser(usr){
var user_info_link=BASE_URL+"/api/user/"+ usr;
var user_info = new XMLHttpRequest();
user_info.onreadystatechange = function() {
if (user_info.readyState == 4 && user_info.status == 200) {
var myArr = JSON.parse(user_info.responseText);
authorOfPost=myArr.data.fullname; // really stuck here not sure how to return this each time to postFeed
}
};
user_info.open("GET",user_info_link);
user_info.setRequestHeader("token",accessTocken);
user_info.setRequestHeader("Content-Type", "application/json");
user_info.send();
}