getJSON function does not return any Data

getJSON function does not return any Data
0.0 0

#1

Can anyone help me figure out why this code doesn’t return any data?

function getQuote(){
var url = “http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
$.getJSON(url, function(data){
$(”.quote").html(’"’ + data.quoteText + ‘"’);
$(".author").html(’~ ’ + data.quoteAuthor);
});
};

Thanks for Help!


#2

Can you post a link to your codepen?

I suspect it’s a CORS issue. Check out your browser console when making the API call.


#3

Here’s the link :slight_smile:


#4

A few other people (here and here) also posted this same error:

Refused to execute script from 'http://api.forismatic.com/api/1.0/...' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I’m not sure how to fix this (and it seems it’s an issue on their side). You need to look for other APIs to use (I don’t know of any though :disappointed_relieved: ) (or just hardcode quotes in your code).


#5

thanks for your help :), anyway, you have some API suggestions?


#6

We are told to use API on this project, I should use it though. :slight_smile:


#7

I’m not aware of this. AFAIK, using APIs is not required. Can you tell me where you read this?


#8

Thanks for this, I’m sorry, I just thought about it, just to master API. hehe Thanks again.


#9

I did find another API It requires a (free) Mashape Marketplace account. I wound up using this one.

Another nice thing about it: it doesn’t seem to require JSONP.


#10

It’s working already using the first one you give :slight_smile: