Hi guys, I’m having a problem with AJAX (maybe, could be something else) with my Random Quote Machine project. I actually finished the project a few months ago and I used jQuery. A few days ago I decided to replace the jQuery with just plan JavaScript. It seemed to be working fine until I realised that for some reason it only works when I have the JavaScript console open (Chrome). I don’t know how or why this is happening but I can’t seem it figure it out.
With the console closed, when I click on the “New Quote” button, nothing happens at all but when I do open the console and click the button, it generates a new quote just fine. I added a line to show the readystate if it’s not 4 and it seems to do 1, 2 and 3 (which is loading) but it never seems to get to 4 unless the console is open. It’s so weird. I also tried Firefox and that doesn’t work at all, even with the console open. However I did notice that it makes requests to the API (and successfully receives new quotes) but it does so constantly (almost like an infinite loop) until I close the tab. But the quote displayed in the document never changes.
You can have a look at my code here: https://codepen.io/ntjnh/pen/QabKNO
If anyone can help me to figure this out, I’d be grateful