Random Quote Machine API Call Error

I’ve been having trouble getting my quotes API to work. Originally, I used the $.getJSON() method, but it didn’t work and I Googled and found code using the .ajax() method with dataType as “jsonp”. Does anyone have a simple explanation for the difference between the two methods?

$(document).ready(function(){ $.ajax( {type: "GET", url: "https://talaikis.com/api/quotes/random/", dataType: 'jsonp', success: function (data){ $("#quote").html(data.quote); }, error: function(){ console.log("error"); } }); });
Using this code, I get the error: " talaikis.com/api/quotes/random/?callback=jQuery32104289845526983025_1495860515078&_=1495860515079:1 Uncaught SyntaxError: Unexpected token :" in the console. Is it saying the API has a syntax error, how do I fix this?

I don’t know enough about the technicalities but, if I’m not mistaken, the API doesn’t actually support CORS (this is a great article, I read it just yesterday when I was trying to get an API to work), or that the callback function is something else (I could be really wrong with the latter). This isn’t entirely surprising because the API seems to be a personal portfolio that isn’t intended for external use.

Your best option is to use another API that is known to work. Alternatively, you could also make a JSON file of quotes, host it somewhere (such as here), and simulate random selection client-side.

I hope that helps. :slight_smile: