【发布时间】:2016-03-16 09:54:43
【问题描述】:
我有一个函数从前端获取输入,然后将该输入连接到我想从维基百科获取的 URL。由于我遇到了 CORS 问题,我将 $http.get 实现为 JSONP,现在我收到以下错误:
angular.js:13236 错误:[$http:badreq] Http 请求配置 url 必须是字符串。已收到: {"方法":"JSONP","url":"https://en.wikipedia.org/w/api.php?action=query&format=json&uselang=user&prop=extracts%7Cpageimages&titles=Maya+Angelou&piprop=name%7Coriginal"}
问题是,他的错误将连接的 url 显示为字符串?
谁能指出我做错了什么?
这是我正在调用的函数:
//function to get author info from wikipedia
$scope.getAuthorInfo = function(author) {
//remove whitespace from author
author = author.replace(/\s/g, '+');
//concat the get URL
var url = 'https://en.wikipedia.org/w/api.php?action=query&format=json&uselang=user&prop=extracts%7Cpageimages&titles=' +
author + '&piprop=name%7Coriginal';
//get author info from wikipedia
$http.get({
method: 'JSONP',
url: url
})
.then(function successCallback(response) {
$scope.author = response.data;
//for every result from wikipedia, trust the extract as html
for (var x in $scope.author.query.pages) {
$scope.author.query.pages[x].extract = $sce.trustAsHtml($scope.author.query.pages[x].extract);
}
}, function errorCallback(response) {
console.log(response);
});
};
如果您需要更多信息,请告诉我。
【问题讨论】:
标签: javascript angularjs