我是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