0

Trying to get json data. 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. I get no errors with this, however, my ajax data does not come in, though in console log it shows the GET worked.

My php displays an encoded json object array which shows up fine when i browse right to it.

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:

image updated!

enter image description here

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. Any help with getting it to show up/advice on what im doing wrong would be great. Thanks in advance.

3 Answers 3

1

I'm going to go ahead and guess that your ajax response didn't have a flightid property located on a flightid property. Have you tried {{ flight }}? Also, in order for the ng-repeat to work, you need to assign an array of objects to $scope.flights

Sign up to request clarification or add additional context in comments.

7 Comments

Just updated my question with a screen shot of my json. I tried flight but still doesn't return me a flightid in my <option></option> element.
is it in an array with potential for other flight objects? it must be in an array for ng-repeat to iterate through. it looks like if it were the first item in an array, you would assign the array "flights" as $scope.flights = flights; and access the flight in the options flight['FieldOpsData']['flightid']
It is a record set with autogenerated id's for flightid. There can only be 1 flight id assigned to a row. Can you please elaborate on what you mean by 'flight['FieldOpsData']['flightid']' in my <options></options> element?
you can't iterate over a set of records if there is only one record and they don't come in a set. I was using bracket notation to access the properties
there has got to be a way to get each flightid. I do not have the option of bringing the flight id's back in an array.
|
1

It's hard to tell without looking at the JSON output, but it seems like this line is incorrect:

$scope.flights = data.flightid;

Did you mean to say?

$scope.flights = data;

10 Comments

i updated my question just a few mins ago with my json. @AlekseyDmitriyev
Data returns me back a bunch of angular erros... $scope.flights = data;
errors say: Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: flight in flights, Duplicate key: string:
I did try this and then it froze my browser... had to force quit it.
we can't debug your screenshot. sorry. from what you're showing, it's not even an array.
|
0

I was able to solve this problem by encoding my row's in json. As stated above in many of the comments, my json was not formatted correctly. In my service I went in and encoded each row individually and it worked like a charm.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.