# Random quote machine API stopped showing results / HELP

**URL:** <https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095>\
**Category:** General\
**Created:** [December 23, 2017, 9:16pm UTC](https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095 "2017-12-23T21:16:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dknvmlhok](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dknvmlhok/32/67443_2.png) [@dknvmlhok](https://forum.freecodecamp.org/u/dknvmlhok)\
**Post date:** [December 23, 2017, 9:16pm UTC](https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095/1 "2017-12-23T21:16:20Z")

</div>

Hi campers. I finished my Random Quote Machine project a while ago.  
Recently I noticed my app stopped showing quotes and author.  
In console everything works just fine with no errors, but not on page.

Here is project-link : [https://codepen.io/dknvmlhok/pen/JOXYvj?editors=0010](https://codepen.io/dknvmlhok/pen/JOXYvj?editors=0010)

Any tips what went wrong? I’d really appreciate help.  
Thank you!

PS: Challenge example uses the same API and their works.

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [December 23, 2017, 10:12pm UTC](https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095/2 "2017-12-23T22:12:48Z")

</div>

> [@dknvmlhok](#):
>
> In console everything works just fine with no errors

Notice that it actually prints a string when you log `quotes`. So probably the API changed the type of data they return from JSON to plain text. You can simply parse that text into JSON with: `JSON.parse(quotes)`.

Not related, but it would make more sense to create a function for the AJAX request. And then run that function both when the page loads and the button is clicked, instead of having duplicate code.

---

<div class="post-metadata">

**Author:** ![dknvmlhok](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dknvmlhok/32/67443_2.png) [@dknvmlhok](https://forum.freecodecamp.org/u/dknvmlhok)\
**Post date:** [December 24, 2017, 12:12pm UTC](https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095/3 "2017-12-24T12:12:41Z")

</div>

Wow it works like charm! Thank you I did not know about the JSON.parse 🙂  
And I created the function like you said and it looks much better. When I wrote the app I was simply happy it worked and didn’t really think about that 😅

So this is my code now

```auto
$(document).ready(function(){
 
  function ajaxCall(){
   $.ajax( {
    type: "GET",
    url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous",
    headers: {
      "X-Mashape-Key": "Kn3fReAYtZmsh5PU6zjic1XxNnadp19EpAtjsnMBh4LNzvnPbc", 
      "Accept" : "application/json"},
    success: function(data){
      let quotes = JSON.parse(data);
      $("#quote, #author").fadeOut(function(){
        $("#quote").html(quotes.quote)
        $("#author").html(quotes.author)
      }).fadeIn();
     
      $("#twitterShare").attr("href", "https://twitter.com/intent/tweet?text="
                              + quotes.quote + "%0a- " + quotes.author)
     }
     });
   } 
  
$("#quoteButton").click(ajaxCall);/*random quote on click the quoteButton*/
$(ajaxCall);/*random quote on document.ready*/
  
});

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:13pm UTC](https://forum.freecodecamp.org/t/random-quote-machine-api-stopped-showing-results-help/165095/4 "2021-01-16T17:13:29Z")

</div>

Closed on January 16, 2021, 5:13pm UTC


