JSON data From Census

I am working with the US Census API and am curious if I am doing this right or if there is a better way to do this.
I am using CORS but could do this with jsonp

The urls and output are


["672591","North Dakota","38"]]


["672591","North Dakota","38"]])

In the case of the first URL I have the following code


Open in new window

The alert produces a string
P0010001,NAME,state,3046355,Iowa,19,672591,North Dakota,38

and the console prints Iowa

My first question is why does Alert make a string and not display object object?

I think I am OK using this jquery as I am able to access the values, but would like to know if any of you experts have concerns about this method.
Who is Participating?
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If your "get" or "post" returns 1 or 10,000 records, they all would show up when you try and output "data".     From there, you would not typically use "data" to display your the output unless for instance the data being returned was not json and instead a short bit of text or  html.  If you do have 10,000 rows of data in json/jsonp it is all on the client machine and you can now access the data many multiple times by calling just the portion of data you need without making more trips to the server.  

10,000 rows of data is more than likely going to be too much and there would be a long initial lag time for all that data to load.   Let's say you do have 10,000 total rows of data, you would probably want to make your ajax call return just several hundred rows at a time.  Then on your actual web page, you may display just 10 rows of data at a time.  You would set up some type of paging that tracks where the user is and at the appropriate spot, call additional data to load similar to this example http://datatables.net/release-datatables/examples/server_side/jsonp.html
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
The reason is your alert is asking for all the data and what you are sending to the console is the 2nd item in the 2nd row of data.  Array's are zero based.  If you used 0,0 instead, you would have seen, P0010001
lvmllcAuthor Commented:
I understand the 0,0 base. I was just surprised that an alert without specifying the array location returns the full data string.

Any comments on if this is the best approach to grabbing this JSON data?
Chris StanyonCommented:
My first question is why does Alert make a string and not display object object?

Because your returned data is an array - not an object!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.