Resources for JSON?

Not at all but looking at it now - it says that your request to the gomix url is “pending”… Have not idea what that means !

I actually removed the crossorigin.me that you put just before and now the network tab shows a nice object :slight_smile:

ALSO in your HTML id is id , not ID

1 Like

I’m back in API hell with the Show the Local Weather project today. Right now I’m in that place where I think I know what I’m doing but it’ll likely fail to work and cause me more anguish than Random Quote did yesterday.

I’m seeing datatype = ‘jsonp’ in your code, which I’m pretty sure should just be ‘json’. You’re also not getting the data from what I see. Under success: is where you should grab the quote and assign it to a variable. The “data” in the function is what’s used to target the api category. So if the api assigns each quote as “quote” then you would say data.quote to target it. I then assigned the api target to a variable, like theQuote = data.quote; and then I was able to use my theQuote variable to use the quotes.

That’s probably really confusing and in this case it’s the blind leading the blind, but that’s the best way I can explain it right now. Hope it helps more than harms >.<

1 Like

I think I’ve got it.

In your success fn, put console.log(data) and you’ll see what you’re dealing with.

for ex this:

 $('#quote-body').append(data["0"].author);

worked fine.

So basically that .append automatically outputs the .author request to the element with the quote-body id, right?

Thanks so much! I must say I don’t understand how the console works, so I don’t exactly see what the problem is. An object appears but there’s something else I’m supposed to understand?

Also, I thought the property name is “quoteAuthor” not sure where “author” comes from

When you console .log you data you should see this in your Console (Ctrl + shift + i):

If you click on the array you see this:

This shows you how to access specific info in that array / data

BONUS: if you click on proto you’ll see the different “methods” or whatever that can be used on our object.

It looks like it though to be honest I’m sometimes confused with .html, .text(), .innerHTML, etc.

With append() you can even append a full HTML element (like a div, a p, …)

Can you point me to a geolocation api or something? My search just keeps coming up with some HTML 5 Geolocation thing that either refuses to work or isn’t being fully explained by people.

I used this : “http://ip-api.com/json” because FCC’s code wasn’t working for some reason.

Had nothing else to do but get data.lat and data.lon to work with (data here being data retrieved from that url).

Great, now I can get it to work! I don’t really understand exactly, but knowing how to use the console now maybe there’s a chance for me to figure it out. Thanks so much for all your help!

long and lat are all I need. Unfortunately ip-api.com seems to be down for me >.<

Honestly it’s been a life-saver for me. I console.log pretty much everything.

Javascript30
gives a lot of tips on how to use the console, it’s free and the videos aren’t long.

1 Like

Nevermind, got in. This should work. Thanks

Im just going to add that the JSON API AJAX section on Colt Steele’s Advanced Web Developer Bootcamp has the best and easiest to understand resources and examples Ive watched/read