So Iโm another in a lengthy row of people who has this issue. There are tons of topics on this matter and sifting through them would be a lengthy process, so please, help the poor guy Back to the point, I wrote JSONP as a result of my research through fCC Reddit, GitHub and some other sites (I understand how to JSON hardcoded stuff but JSON APIs is somewhat a dark matter for me ). Here is my code based on Rafase282 example and some tips from Reddit and forismatic.com. I click on the button and it only changes bg colors, no quotes visible. What went wrong?
$(document).ready(function(){
$.ajaxSetup({ cache: false });
var url = โhttps://crossorigin.me/http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=jsonp&lang=enโ;
var newQuote = function(data){
$(โ#quotetextโ).text(data.quoteText);
var tweet = โhttps://twitter.com/intent/tweet?text=โ + data.quoteText + โ Author โ + data.quoteAuthor;
if (data.quoteAuthor === โโ) {
data.quoteAuthor = โUnknownโ;
}
$(โ#quoteauthorโ).text(โAuthor: โ + data.quoteAuthor);
$(โ#tweetโ).attr(โhrefโ, tweet);
};
$.getJSON(url, newQuote, โjsonpโ);
colors for bg
var colors = [โ#16a085โ, โ#27ae60โ, โ#2c3e50โ, โ#f39c12โ, โ#e74c3cโ, โ#9b59b6โ, โ#FB6964โ, โ#342224โ, โ#472E32โ, โ#BDBB99โ, โ#77B1A9โ, โ#73A857โ];
on click JSON and color change
$(โbuttonโ).on(โclickโ,function(){
$.getJSON(url, newQuote, โjsonpโ);
var randomColors = Math.floor(Math.random() * colors.length);
$(โbody, .btnโ).css(โbackground-colorโ, colors[randomColors]);
$(โ#quotetextโ).css(โcolorโ, colors[randomColors]);
});
});