【问题标题】:Javascript and angularjs can't handle http.get with https urlJavascript 和 angularjs 无法使用 https url 处理 http.get
【发布时间】:2015-07-25 16:13:37
【问题描述】:

我正在编写 JavaScript 和 AngularJS 代码,并试图通过 https 网站获取一些 JSON 数据。

我的代码:

var app = angular.module('myApp', []);
app.controller('DecisionsCtrl', function($scope, $http) {
    $http.get('https://test3.diavgeia.gov.gr/luminapi/opendata/search.json?org=10599')
    .success(function (response) {$scope.decisions = response.decisions;});
});

  <tr ng-repeat="x in decisions | limitTo:10 ">
    <td>{{x.protocolNumber }}</td>
    <td>{{x.subject}}</td>
    <td>{{x.extraFieldValues.financialYear}}</td>
    <td>{{x.extraFieldValues.budgettype}}</td>
  </tr>
</table>

通过 Firefox 控制台出错的图片:

如果我使用 http 网站,或者如果我将 https 的东西下载到 file.json 中,没有任何问题。

谁能帮帮我?

【问题讨论】:

  • 你看到底部的两个警告了吗?尤其是第二个“Cross-Origin Request Blocked”
  • google the terms used in last error .....会找到成千上万的结果

标签: javascript json angularjs https


【解决方案1】:

您的请求被 CORS 阻止:https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

如果您控制服务器,则可以添加“Access-Control-Allow-Origin”标头以允许您尝试访问它的主机。

如果您不控制服务器,请联系管理员并要求他们添加它,或者他们可能有其他访问方式(例如 JSONP)。

【讨论】:

  • 我将联系他们(不是我的服务器)并要求他们添加它。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-08
  • 2017-09-28
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多