0

Here's my ajax call:

jQuery.ajax({
    type:  'GET',
    datatype: 'application/json',
    url:   URL,
    dataType: 'jsonp',
    success: function(data) {
         console.log(data);
    },
    error: function(data) {
         console.log(data);
        }
 });

When I click on network in Chrome Developer tools, I see a status 200, and the response data is all there, but it doesn't console log it out anyway that I try. Instead, here is what I get:

Refused to execute script from 'http://localhost:3000/api/bikes?apiKey=*****&callback=jQuery17204357656354550272_1423492504648&_=1423492968710' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
VM1680:11 Object {readyState: 4, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}

Any explanation?

TheJKFever
  • 685
  • 7
  • 25
  • Why are you attempting to specify 2 datatypes? jsonp should be the datatype specified for cross domain requests - I think you should remove `dataType: 'jsonp'` in your case. – Davie Brown Feb 09 '15 at 14:59
  • This is a cross domain request – TheJKFever Feb 10 '15 at 00:32
  • Take a look here: http://stackoverflow.com/questions/24528211/refused-to-execute-script-from-because-its-mime-type-application-json-is - seems like a very similar issue to yours. – Davie Brown Feb 10 '15 at 11:07

1 Answers1

0

Please try to use 'json' instead of 'jsonp'

If the 'URL' does not return a callback function as expected for 'jsonp', you need to use 'json' instead of 'jsonp'

jQuery.ajax({
    type:  'GET',
    datatype: 'application/json',
    url:   URL,
    dataType: 'json',
    success: function(data) {
        console.log(data);
    },
    error: function(data) {
        console.log(data);
    }
});
Francis Au
  • 56
  • 4
  • The problem with using json is that then I get a CORS error. – TheJKFever Feb 10 '15 at 00:31
  • If your very requirement is to overcome XMLHttpRequest same domain policy, I recommend you to have a look _here_ http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp – Francis Au Feb 10 '15 at 02:37