我是Angularjs的新手,并试图遵循在httpjget上给出的有关angularjs网站文档的示例。
我有一个REST服务,该服务调用的返回数据时,如下所示:
http://abc.com:8080/Files/REST/v1/list?&filter=FILE
{
"files": [
{
"filename": "a.json",
"type": "json",
"uploaded_ts": "20130321"
},
{
"filename": "b.xml",
"type": "xml",
"uploaded_ts": "20130321"
}
],
"num_files": 2}
我index.html文件的部分内容看起来如下:
<div class="span6" ng-controller="FetchCtrl">
<form class="form-horizontal">
<button class="btn btn-success btn-large" ng-click="fetch()">Search</button>
</form>
<h2>File Names</h2>
<pre>http status code: {{status}}</pre>
<div ng-repeat="file in data.files">
<pre>Filename: {{file.filename}}</pre>
</div>
而我的JS文件看起来如下:
function FetchCtrl($scope, $http, $templateCache) {
$scope.method = 'GET'; $scope.url = 'http://abc.com:8080/Files/REST/v1/list?&filter=FILE';
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
}
但是,当我运行这个,我看不到任何文件名的结果,我见HTTP状态代码= 0
当我运行,
http://abc.com:8080/Files/REST/v1/list?&filter=FILE在浏览器中,我仍然可以看到所希望的结果(如上所述)
我甚至试图在Firefox使用萤火虫调试,我看到上述URL被调用当我点击“搜索”按钮但响应看起来是空的。有趣的是在URL下的萤火虫,它显示
OPTIONS "Above URL"
代替
GET "Above URL"
能否请您让我知道,我在做什么错的,为什么我不能够访问JSON数据?
感谢,
嘿,我知道这已经有一段时间了,但是你有没有深究过这个问题的底部?接受的答案在Firefox或Chrome中不适用于我。它仍然在调用OPTIONS。 – tbogatchev 2015-03-16 20:53:43