2
votes

I am trying to get data((some quotes) from forismatic api but i am not getting any response. I am using ajax in jquery, but i am getting the following error in my console:

Refused to execute script from 'https://api.forismatic.com/api/1.0/?&callback=jQuery32105928698091179365_1493889543432&method=getQuote&format=jsonp&lang=en&jsonp=?&_=1493889543433' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I know this question has been asked already but i am not getting what should i do, i tried everything but still this error is coming. I also tried CORS but i think i am doing somewhere something wrong as i am very new to jquery so my concepts are not clear yet. Can anyone please tell me how to solve this problem, i kind of understood the problem but i don't know how to solve it. Any help will be appreciated thanku!

This is my js file containing the function:

function getQuote(){
  $.ajax({ 

    url:'https://api.forismatic.com/api/1.0/?' + '&callback=?',
    dataType:'jsonp',
    data : 'method=getQuote&format=jsonp&lang=en&jsonp=?',
    success: function(response){
      $('.load').hide();
      $('blockquote').show();
      $('#quoteText').html(response.quoteText);
      
      if(response.quoteAuthor !== ''){
        $('#quoteAuthor').html(response.quoteAuthor);
      }
      else{
        $('#quoteAuhtor').html('Unknown')
      }
    }
    
  });
};
1

1 Answers

0
votes

It looks like you're out of luck here - changing your format from JSONP to JSON won't work, as the Forismatic API doesn't output the CORS header, so the browser will block this. And now JSONP isn't working because Forismatic isn't outputting the correct content type.

According to this forum post, that API is no longer supported. Other people are having the same problem and there's no fix - so it's time to look for a different API unfortunately.