简体   繁体   English

HTTP GET在AngularJS中不起作用?

[英]HTTP GET not working in AngularJS?

Here is my controller, being served from localhost port 80: 这是我的控制器,从本地主机端口80提供服务:

function ListCtrl($scope, $http) {
    $http.get('/api/moz').success(function (data) {
        $scope.moz = data;
    });
}

And the output from curl: 以及curl的输出:

curl -i localhost/api/moz
HTTP/1.0 302 Found
Date: Tue, 21 May 2013 13:35:43 GMT
Server: WSGIServer/0.1 Python/2.7.4
Content-Type: application/json

[{"sID": 0, "sName": "Sa"},{"sID": 0, "sName": "Ab"},{"sID": 0, "sName": "Ds A"}]

Unfortunately the output from {{moz}} is [] . 不幸的是{{moz}}的输出是[]

Been working on this for many hours now, and have no clue how to get it to work. 现在已经为此工作了多个小时,并且不知道如何使其工作。 My scaffold is identical to step5 of the angularjs tutorial. 我的支架与angularjs教程的step5相同。

You're retrieving an array, and need to iterate over it. 您正在检索数组,并且需要对其进行迭代。 Try this in your template: 在您的模板中尝试以下操作:

<ul>
 <li ng-repeat="m in moz">{{m.sName}}</li>
</ul>

Looks like the only status-code supported by the success promise function is 200. 看起来success承诺函数支持的唯一状态码是200。

So going against the standard I have made all my "successful" returns HEAD 200. 因此,违反标准,我已使所有“成功”返回HEAD 200。

It is now working. 现在正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM