2015-08-09 190 views
1

当我尝试通过过滤器从我的WordPress wp-json中获取信息时,我得到以下响应:拒绝执行来自'....“的脚本,因为它的MIME类型(“应用/ JSON”)不是可执行文件,并严格MIME类型检查被启用。angular:json返回“拒绝执行脚本”

var newsApi = 'http://mywebsite.com/wp-json/?filter[category_name]=news?_jsonp=JSON_CALLBACK'; 

// This should go in a service so we can reuse it 
$http.jsonp(newsApi). 
    success(function (data, status, headers, config) { 

     $scope.news = data; 

     console.log(data); 
    }). 
    error(function(data, status, headers, config) { 
     console.log('Post load error.'); 
    }); 
+2

'URL'必须具有'callback = JSON_CALLBACK'作为查询参数,url应该像'http://mywebsite.com/wp-json/?filter [category_name] = news?_jsonp = JSON_CALLBACK&callback = JSON_CALLBACK' –

+1

另外我我不确定,但在URL中有两个'?'。可能第二个必须是'&'? –

+0

谢谢!有用 – user3581731

回答

0

@Pankaj Parkar的回答为我工作。我不得不添加?callback=JSON_CALLBACK到url的末尾。

这是我的Angular应用程序中的API调用。 $http.jsonp('https://api.forecast.io/forecast/MY_API_KEY/' + lat + ',' + lng + '?callback=JSON_CALLBACK')

相关问题