Random quote generator project!

Random quote generator project!
0.0 0

#1

Hello, i am building my first project but i am stuck at implementing the API with jQuery, i am trying to do it step by step like the lessons but it doesn’t works, even showing the content with .stringify! Can you give me some tips?

Regards :slight_smile: !


#2

Could you post a link to your project?
It’s hard to give any kind of useful advice based on your description alone.


#3

https://codepen.io/Stivi7/pen/qXRReW?editors=1010 here is my code, i have seen different references and tutorials but still doesnt work, it is driving me crazy!

thanks in advance :slight_smile:


#4

You forgot to import jQuery.
If you haven’t used codepen before, just click on the gear next to the Javascript field, and use quick-add to select it.
Also, depending on whether you’re using https everywhere or not, you might have a problem calling an http link. If that’s the case, simply change the ajax request link from http to https.

I hope that helps!


#5

I imported jQuery now but still nothing :confused: where can i change the ajax request link?


#6

At $getJson.
Try:

$.getJSON(“https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=”, function(data){
$(".message").html(data[0].content + " - " + data[0].title)

instead of:

$.getJSON(“http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=”, function(data){
$(".message").html(data[0].content + " - " + data[0].title)

It worked for me after importing jQuery, and changing that.


#7

thanks man, i love you :smiley: such a great help :slight_smile:


#8

No problem!
Have fun coding!


#9

I prefer that method rather than using ajax to view APIs.