我正在尝试让一个与AngularJS一起工作。控制台不会抛出错误,也不会以任何方式工作。有人可以帮助您吗?
$scope.click = function() {
$http.jsonp('https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search& gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=test&callback=JSON_CALLBACK')
.success(function(data) {
var results = data.query.pages;
angular.forEach(results, function(v,k) {
$scope.articles.push({title: v.title, body: v.extract})
})
})
.error(function () {
alert("error");
})
};
来自角文档您不能再将JSON_CALLBACK字符串用作占位符,以指定回调参数值应在哪里。
var url = "https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search& gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=test";
$sce.trustAsResourceUrl(url);
$scope.click = function() {
$http.jsonp(url, {jsonpCallbackParam: 'callback'})
.success(function(data) {
var results = data.query.pages;
angular.forEach(results, function(v,k) {
$scope.articles.push({title: v.title, body: v.extract})
})
})
.error(function () {
alert("error");
})
};