I have a function that takes input from the front-end and then concatenates this input to the URL that I want to get from Wikipedia. Since I had problems with CORS, I implemented my $ http.get as JSONP, and now I get the following error:
angular.js: 13236 Error: [$ http: badreq] The Http request configuration URL must be a string. Received: {"method": "JSONP", "url": " https://en.wikipedia.org/w/api.php?action=query&format=json&uselang=user&prop=extracts%7Cpageimages&titles=Maya+Angelou&piprop=name% 7Coriginal "}
Is the fact that his error shows a concatenated url as a string?
Can anyone point out what I'm doing wrong?
This is the function I call:
$scope.getAuthorInfo = function(author) {
author = author.replace(/\s/g, '+');
var url = 'https://en.wikipedia.org/w/api.php?action=query&format=json&uselang=user&prop=extracts%7Cpageimages&titles=' +
author + '&piprop=name%7Coriginal';
$http.get({
method: 'JSONP',
url: url
})
.then(function successCallback(response) {
$scope.author = response.data;
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);
});
};
If you need more information, please let me know.
source
share