function profileGen(username, container) { queryAPIByUser("", username, (user) => { parseOrgs(user.login).then( (orgsReturn) => { let html = "
\ \
\
\
\
"+user.name+"
\
"+user.login+"
\
\
\
\ \
\
\
\
\

"+user.html_url+"

\ " + (user.blog != null ? "

"+user.blog+"

" : "")+" \
\
\ \
" $("#"+container).html(html); }) }, () => { console.error("error getting user info"); }); } function parseOrgs(name) { return new Promise( (resolve, reject) => { let urlpath = `api/users/${name}/orgs`; let orgs_final = []; queryUrl(urlpath, (orgs) => { var prom= []; for(var i = 0;i < orgs.length; i++) { prom.push( new Promise( (res, rej) => { url = orgs[i].url; queryUrl(url, (orgData) => { orgs_final.push(""); res(); }, (error) => { console.log(error); rej(error); console.error("error getting org info"); }); }) ) } Promise.all(prom).then(function() { resolve(orgs_final.join(" ")); }) }, (error) => { console.error("error getting orgs"); reject(error); }); }) } function queryUrl(url, successCallBack, errorCallBack) { url = url.split("https://api.github.com/").join("api/"); $.ajax({ type:'GET', url: url, crossDomain: true, dataType: "json", success: successCallBack, error:errorCallBack, timeout: 3000 }); } function makeUrl(user) { return "/FriendsGraph.html?name="+user; }