Codepen and AJAX - Random Quote Machine Help

Hi @ all,

can somebody please explain what jsonp=? in data: "method=getQuote&format=jsonp&lang=en&jsonp=?", is doing?

I guess it has something to do with the callback function, but can’t quite figure it out.

Thanks.

Cheers,
Matt

I have very similar issues and the following JS in my Codepen but I have no clue what I’m doing wrong - error I’m getting is “No ‘Access-Control-Allow-Origin’ header is present on the requested resource”. I thought this was a CORS error but I’ve tried a few CORS urls now and nothing seems to work.

JS:
$(‘#new-quote-button’).click(function() {

$.ajax({
url: “https://cors-anywhere.herokuapp.com/http://api.forismatic.com/api/1.0/?”,
dataType: “json”,
data: “method=getQuote&format=json&lang=en”,
success: function(data) {
$(‘#quote’).text(JSON.stringify(data));
},
})

});

it seems to be ok. i don’t know whatkind of issue there could be, Do you have the codepen link ? Ican have a look

Ok thanks because without you I wouldn’t have discovered my stupid mistake! Once you confirmed this was ok I went back and emptied my p tag #quote of placeholder text in the html side and it worked! This is great! :smiley:

1 Like

Thank you so much for this. I’ve spend 5 hours on this using a non-working proxy. Feeling like an idiot re-reading through everything re-checking my code , and you’ve made it work :slight_smile:

1 Like