【发布时间】:2017-07-31 02:23:28
【问题描述】:
Angular 1.6.3 不允许 1.5.8 中允许的请求,我收到此错误:
$sce:insecurl
Processing of a Resource from Untrusted Source Blocked
完整的错误可用here。
我想将我的 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
【问题讨论】:
标签: javascript angularjs jsonp angularjs-http angularjs-1.6