APIs - Please help :'(

Hey

I’m really struggling on the random quote generator API and am looking for help. I’ve worked on it all today/yday trying to find a solution but I can’t seem to find out.

Right now I don’t want to format the data, I just want to get my data into the header! I’ve copied the url into a browser which brings up a random quote, I’ve also passed the $.getJSON into the console which did bring in some data, but then I couldn’t get the button/click event to work to pass through to the header.

If this is a button issues over a JSON query I will be very upset…

what kind of console errors if any are you getting? I am looking at it now and am getting some, but wondering what you are seeing and what you have tried so far?

EDITED to add: I know you’ve been trying all day…what’s showing RIGHT NOW in your console?

Sorry, I don’t think I understand - currently if I click the button, nothing happens. Nothing comes in the console either.

If, however I put the following section of code into the console:

$.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en&callback=?", function(json) {
console.log(json); });

Then I get a bit object of stuff that looks like this:

Object
-abort: function (a){-}
-always: function(a)[-]
-catch function(a)[-]…

…and it goes on for a while.

what browser are you using?

Safari, I’ve not tried anything else tbh

I’m getting some different console errors in Chrome, but can’t get past this error even when I address a few other ones:

Refused to execute script from 'https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en&callback=jQuery31104296265560980701_1493763287940&_=1493763287941' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

I know this is an error that’s come up a lot and I’ve not been successful yet fixing it (having just spent 10-15 min on it). Reading this now:

The console should be showing you errors. Try using chrome for it’s debugging tools for a few projects.

Try running my pen (a fork of yours) in safari or mozilla, does it work for you?

And, I’ve decided i’m not uptodate on Cross origin requests to troubleshoot this further today. :frowning:

But try using a different browser with better deloper tools like firefox or chrome and see if you get any progress. sorry i could not help more.

Does this work for you?
I am not too sure what is not working for you. I just replace my API address and it works.

One more thing, codepen doesn’t work for me in Safari. It look all distorted. :frowning:

yeh that one works. Ive tried it in Chrome as well but its the same as safari. I get nothing in the codepen console, i don’t know if I’m doing it wrong or looking in the wrong place, but console is always blank unless i type into it myself.

http://api.jquery.com/jquery.getjson/

$.getJSON( API, function( ), 'jsonp' );
//add the jsonp part in the mix

and then

add this before your api address. This prevents cross-origin issue. Suggest that you look up what that means so you know what it is. https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

"https://cors-anywhere.herokuapp.com/"

But you are still not done. There is one more issue.
I’ll let you figure that one out :smiley:

1 Like

this looks really nice and clean, good work! I tried implementing your solution in a fork of the OP’s pen, and I still can’t get it to work. Can you spot any errors here? Even though i’ve done this project, I’d still like to konw why I can’t fix the OPs pen!

There was a similar question yesterday, and this was the answer:

The OP API has a callback with no values on it. Remove that it works.

Hi guys

Thanks for all your help. Unfortunately I still couldn’t get it to work. I tried Chrome, putting in jsonp, putting in the heroku line, removing the callback section, trying the other example api and i got nothing. I’m going to try something else for a while before my computer goes out the window.

Thanks again for your input though, all your efforts to help are very much appreciated!

1 Like

Hey Pal,

Don’t worry about it Im on the weather app and the JSON call is a nightmare… theres some technical wizardry we weren’t prepared for, if you simply followed the lessons.

My suggestions is start “googling” AJAX JSON call et al… are try and teach yourself this stuff from multiple angles/sources.

On the plus side, this is where most of the “Theory” starts to sink in (and all the jibber jabber will start to have meaning)… it will roll around your head and you’ll start thinking about it from multiple angles.

Good luck… remember they put a picture up of someone punching their screen for a reason. :slight_smile:

1 Like

Haha, cheers bud. one day I’ll build my confidence back up to try the weather one!