[Solved] Random Quote Machine - onclick only fires once

[Solved] Random Quote Machine - onclick only fires once
0

#1

I’m successfully pulling a random quote from an API, but I’m only able to pull one. Clicking the button more than once does nothing.

I’ve searched around, but I can’t find a clear answer. Any idea what’s causing this?

Please excuse the ugliness. I haven’t started styling the app yet.

Link: http://codepen.io/JoshAmore/pen/LWPpWq

Thanks all!

Update: My request was getting cached (pulling one quote and keeping it). I had to turn off cache for this function. This Stack Overflow question helped clear up the issue. Thanks again for all the helpful answers – this community is awesome :+1:


#2

onclick and its callback function are fine, with that in mind, the cause of problem seems to be your API parameters. Apparently, you are receiving the same quote on each request. I’d suggest that you consult with the API document.

Edit: I was wrong on that, as others pointed out the problem was cached request giving you same response.


#3

Most likely the request is cached. You can disable cache if you use jQuery or add a random parameter to your request.


#4

I had the same issue untill I added this code to my pen.

$(document).ready(function() {
  $.ajaxSetup({
    cache: false
  });

What it does, as fas as I understand - it tells ajax not to cache information it’s got. Hope it helps.


#5

Thanks for the help!


#6

This was my problem. Thanks for the nudge in the right direction!


#7

That was my problem.