Angular jsonp request coursera api giving error

The following error is given when I try to request coursera api with jsonp method in Angular.

Refused to execute script from 'https://api.coursera.org/api/courses.v1?callback=angular.callbacks._0' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

I have gone through the other answers but could not find the correct solution.

This is my code which I think is done correctly as it fetches other CORS resources successfully. I dont know whats going on with coursera api.

var deferred = $q.defer();
var url = "https://api.coursera.org/api/courses.v1?callback=JSON_CALLBACK";
$http.jsonp(url).success(function(data) {
  deferred.resolve(data);
  })
  .error(function(data, status, headers, config) {
    deferred.reject(status);
    });
return deferred.promise;

Refused to execute script … because its MIME type ('application/json') is not executable

The URL https://api.coursera.org/api/courses.v1?callback=JSON_CALLBACK is returning JSON, not JSONP.

When you make a JSONP request, the server has to respond with JSONP formatted data (which is a particular form of JavaScript script). The server you are talking to does not.

This is my code which I think is done correctly as it fetches other CORS resources successfully.

JSONP is what we used before CORS existed. It is a clever, but dirty, hack with some security implications.

If you can use CORS instead, use CORS instead. (The server does not appear to grant CORS permissions either, which leaves you having to get the data via another server instead of directly from the client)

链接地址: http://www.djcxy.com/p/47604.html

上一篇: jsonp函数不起作用

下一篇: Angular jsonp请求coursera api给出错误