- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Display $.getJSON information
Hey guys,
I’m in the process of trying to display information from a JSON file that will list each bit in a li tag. Everything went great, but when I make my call to the JSON file, the only thing being display is [object Object]. Looking into the object I can see what the data I need but I’m not sure how to get it onscreen at this point. Any tips would be extremely useful. I’ll include the code I’m using to make the call below. Sorry it looks like hell. Every time I try to use the block code option it messes things up. Thanks guys.
$.getJSON(‘/assets/shared/misc/counties.json’, function(json) {
var states = [];
states.push(json);
$(‘.state-names li’).each(function(index) {
$(this).text(states[index]);
});
console.log(states);
});
JSON.stringify()?
If you’re talking about $(this).text(states[index]);
:
states[index]
is your json response. Maybe it’s an object…? That would make sense, judging by your description. What does your response look like?
Also, is there a reason you’re putting the response into an array before using it (it would seem that array would only ever have the one item, so I’m not sure what the point is)?
What does you actual response look like (i.e., do console.log(json)
)?