Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Garrett Sanderson
12,735 PointsAJAX Request pulling information from arrays with objects and arrays with in them
I need some help getting with an ajax request that I am messing around with. Currently I have this as my ajax call
$.ajax({
type: 'GET',
url: 'https://teamtreehouse.com/garrettsanderson.json',
dataType: 'json',
success: function(treeHouseDatas) {
var data = JSON.stringify(treeHouseDatas)
$.each(treeHouseDatas, function(i, treeHouseData) {
$('#treehouse-info').append('<p>' + treeHouseData + '</p>');
console.log(treeHouseData);
});
}
});
The response I am getting in the console is as follows:
Garrett Sanderson
undefined
garrettsanderson
undefined
https://teamtreehouse.com/garrettsanderson
undefined
https://uploads.teamtreehouse.com/production/profile-photos/194972/avatar_about-me-photo.png
undefined
ed16b4c7fd1211bd25b61bb9efd2d3cf
undefined
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]0: Object1: Object2: Object3: Object4: Object5: Object6: Object7: Object8: Object9: Object10: Object11: Object12: Object13: Object14: Object15: Object16: Object17: Object18: Object19: Object20: Object21: Object22: Object23: Object24: Object25: Object26: Object27: Object28: Object29: Object30: Object31: Object32: Object33: Object34: Object35: Object36: Object37: Object38: Object39: Object40: Object41: Object42: Object43: Object44: Object45: Object46: Object47: Object48: Object49: Object50: Object51: Object52: Object53: Object54: Object55: Object56: Object57: Object58: Object59: Object60: Object61: Object62: Object63: Object64: Object65: Object66: Object67: Object68: Object69: Object70: Object71: Object72: Object73: Object74: Object75: Object76: Object77: Object78: Object79: Object80: Object81: Object82: Object83: Objectlength: 84_proto_: Array[0]
Newbie
The actual JSON File looks like this
{
name: "Garrett Sanderson",
profile_name: "garrettsanderson",
profile_url: "https://teamtreehouse.com/garrettsanderson",
gravatar_url: "https://uploads.teamtreehouse.com/production/profile-photos/194972/avatar_about-me-photo.png",
gravatar_hash: "ed16b4c7fd1211bd25b61bb9efd2d3cf",
badges: [],
points: {}
}
How do I access the badges array and the points object? As of right now I just get the Object, Object spitting out.
Any help would be much appreciated!
Thanks!
1 Answer
Garrett Sanderson
12,735 PointsNevermind. I figured it out.
I could target the badges array straight up front.
treeHouseDatas.badges