I am currently creating a quotation machine using the forismatic API, and is completely dead end. My program worked fine until I decided to review my work in the future. Here is my code:
var html = "http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?"; var getQuote=function(data){ if(data.quoteAuthor === "") { data.quoteAuthor = "Unknown"; } $('#author').text(data.quoteAuthor); $('#text').text(data.quoteText); var quote = 'https://twitter.com/intent/tweet?text=' + "\"" + data.quoteText + "\"" + ' Author: ' + data.quoteAuthor +' @Gil_Skates'; $('#tweet').attr("href", quote); }; $(document).ready(function() { $.getJSON(html, getQuote, 'jsonp'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class = "quote-box centered"> <div class = "quote-text"> <i class="fa fa-quote-left"></i><span id = "text" >Quotes inspire<span> </div> <div class = "quote-author"> <span id = "author">Programmer</span> </div> <div class = "buttons"> <a class="button" href="https://twitter.com/intent/tweet" data-size="large" id="tweet" title="Tweet this now!" target="_blank"> <i class = "fa fa-twitter"></i> </a> <button class = "button" id ="new-quote">New Quote</button> </div> </div>
What am I doing wrong? I created a variable to hold my url, created a function that receives data, and used getJSON to use my function. (Sorry for my terminology)
It works when I run it on this website, but on: https://codepen.io/gilioo/pen/JKpjgr it does not generate a quote.
Any help is appreciated.
source share