Angular1.6.3
不允许允许的请求,1.5.8
我收到此错误:
$sce:insecurl
Processing of a Resource from Untrusted Source Blocked
完整的错误可在此处获得。
我想升级我的 angular 版本1.6.3
以获得最新最好的,但我依赖于这个 API。我有没有办法将其标记为受信任的 API 或使用此 API 的其他方式?导致这种情况的这两个版本之间有什么区别?
这是我要运行的代码:
var app = angular.module('app', []);
app.controller('firstController', ['$http', function($http) {
console.log('firstController up and running');
var key = 'XXXXXXXXXXXXX'; // is an actual key
var self = this;
self.animal = {};
self.getRandomPet = function(){
var query = 'http://api.petfinder.com/'; // baseURL for API
query += 'pet.getRandom'; // selecting the method we would like to return
query += '?key=' + key; // Giving petfinder our key
query += '&format=json'; // Telling petfinder we want our response to be JSON
query += '&output=basic'; // Telling petfinder what data we want (more than just id)
var request = encodeURI(query) + '&callback=JSON_CALLBACK'; // removing spaces and special characters from response as well as making jsonp work with the callback
console.log('Request:', request);
$http.jsonp(request).then(function(response){
console.log(response);
self.animal = response.data.petfinder.pet;
});
}
self.getRandomPet();
}]);
整个存储库可在此处获得:https ://github.com/LukeSchlangen/angular-petfinder-api