简体   繁体   English

AngularJS $ Http服务到GET json没有显示

[英]AngularJS $Http Service to GET json Not Showing

Trying to get json data. 试图获取json数据。 Originally created an ajax requests that works in a regular html page but not in my angular app so I decided to try the built in $http get function. 最初创建了一个在常规html页面中工作但不在我的角度应用程序中的ajax请求,所以我决定尝试内置的$ http get函数。 I get no errors with this, however, my ajax data does not come in, though in console log it shows the GET worked. 我没有得到任何错误,但是,我的ajax数据没有进入,但在控制台日志中它显示GET工作。

My php displays an encoded json object array which shows up fine when i browse right to it. 我的php显示一个编码的json对象数组,当我浏览它时,它显示正常。

My controller looks like: 我的控制器看起来像:

    apDash.controller('fieldopmgrController', function($scope,$http){
        $http.get('protected/getHeadObs.php')
            .success(function( data, status, headers, config ) {
        $scope.flights = data.flightid;
           });  
    });

My view looks like: 我的观点如下:

    <div class="small-5 columns"> 
       <label>Flight ID
          <select name="fliID" class="radius">
          <option ng-repeat="flight in flights">{{flight.flightid}}</option>
          </select>
       </label>
    </div>

My json looks like: 我的json看起来像:

image updated! 图片更新了!

在此输入图像描述

Again, i get absolutely no errors in my console log but yet my view does not work. 再次,我在我的控制台日志中完全没有错误,但我的视图不起作用。 Been toying with AngularJS for a few months but this is my first time im using the $http service. 一直在玩AngularJS几个月,但这是我第一次使用$ http服务。 Any help with getting it to show up/advice on what im doing wrong would be great. 任何帮助让它出现/建议我做错什么都会很棒。 Thanks in advance. 提前致谢。

I'm going to go ahead and guess that your ajax response didn't have a flightid property located on a flightid property. 我要继续猜测你的ajax响应没有一个位于flightid属性上的flightid属性。 Have you tried {{ flight }} ? 你试过{{ flight }}吗? Also, in order for the ng-repeat to work, you need to assign an array of objects to $scope.flights 此外,为了使ng-repeat有效,您需要为$scope.flights分配一个对象数组

It's hard to tell without looking at the JSON output, but it seems like this line is incorrect: 不看JSON输出很难说,但看起来这行不正确:

$scope.flights = data.flightid;

Did you mean to say? 你的意思是说?

$scope.flights = data;

I was able to solve this problem by encoding my row's in json. 我能够通过在json中编码我的行来解决这个问题。 As stated above in many of the comments, my json was not formatted correctly. 如上面许多评论所述,我的json格式不正确。 In my service I went in and encoded each row individually and it worked like a charm. 在我的服务中,我进入并单独编码每一行,它就像一个魅力。

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

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