【问题标题】:angular: json returns "Refused to execute script"角度:json返回“拒绝执行脚本”
【发布时间】:2015-11-01 06:58:04
【问题描述】:

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

 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.' );
  });

【问题讨论】:

  • URL 必须有 callback=JSON_CALLBACK 作为查询参数,url 应该类似于 http://mywebsite.com/wp-json/?filter[category_name]=news?_jsonp=JSON_CALLBACK&callback=JSON_CALLBACK
  • 我也不确定,但你的 URL 中有两个 ?。可能是第二个必须是&

标签: json angularjs wordpress rest


【解决方案1】:

@Pankaj Parkar 的回答对我有用。我必须在网址末尾添加?callback=JSON_CALLBACK

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-27
    • 2020-02-12
    • 2014-09-03
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    相关资源
    最近更新 更多