简体   繁体   中英

Illegal use of JSON_CALLBACK in url angular Js

My goal is to fetch an RSS feed But always I get this error

Error: [$http:badjsonp] Illegal use of JSON_CALLBACK in url

 angular.module('djsreaderApp') .controller('MainCtrl', function($scope, $http,$sce) { var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fdailyjs.com%2Fatom.xml'%20and%20itemPath%3D'feed.entry'&format=json&diagnostics=true&callback=JSON_CALLBACK"; $http.jsonp($sce.trustAsResourceUrl(url)). then(function(data, status, headers, config) { $scope.feed = { title: 'DailyJS', items: data.query.results.entry }; }); }); 

You need to update $http call like

$http.jsonp(url).then(function(data) {
    console.log(data);
    $scope.feed = {
        title: 'DailyJS',
        items: data.query.results.entry
    };
});

Working fiddle

You need to explicitly specify the call back parameter in the $http call and remove it from the end of the URL.

var url = "http://query.yahooapis.com/v1/...&diagnostics=true";

$http({
  url: $sce.trustAsResourceUrl(url)),
  method: 'jsonp',
  jsonpCallbackParam: 'JSON_CALLBACK'
}).then...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM