Quote Generator - Same Quote Displays

Hi! I’m currently working through creating the Random Quote Machine using this API: https://quotesondesign.com/api-v4-0/.

I created an xmlHTTPRequest but keep getting the same quote to display. I’ve tried separating the different steps in the request to see if I could do a completely separate request but that didn’t seem to work.

I could really use some help even if it’s just a nudge in the right direction. I’m also open to any advice on how to improve it.
Here’s a link to my Codepen and thanks in advance!

Quotesondesign caches the results, so you will keep getting the same quote after the first request for the same url unless you “trick” the API. If you assign a random querystring variable onto the end of the url, you should get a new quote.

For example. below is your current url:

var url = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";

Create a random number and assign it to a new variable, the concatenate the new variable onto the end of the existing url with a bogus querystring variable like so:

url += "&bogusQSvar=" + myRandomNumber; // assumes you leave your original url string as declared above

That worked, thanks! I wasn’t aware you could do that. Is that specific to this API?

Other APIs may cache the results. Typically it will be in the documentation somewhere, but in this case, I just know from experience in working with this particular API.

I see, thanks for your help! I’m trying to learn more about programming and using APIs but got stuck on this. It seemed pretty small at first, but I couldn’t find a solution after digging around. Just for future reference in case I get stuck again. How’d you go about figuring it out?