Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my code i use angular (material) autocomplete and i need to get data from external php file.

HTML:

HTML
<div ng-controller="search_interest" layout="column">
  <md-content class="md-padding" layout="column">

      <md-autocomplete 
        md-selected-item="selectedItem" 
        md-search-text="searchText" 
        md-items="item in getInterest1(searchText)" 
        md-item-text="item.name" 
        placeholder="Search for a vegetable">
        <span md-highlight-text="searchText">{{item.name}} :: {{item.type}}</span>
      </md-autocomplete>

  </div>


When i return an "handmade" JSON, autocomplete works well:

JavaScript
//RETURN: results [{"name":"Broccoli","type":"Brassica"}]
    $scope.getInterest1 = function() {
      var results = [
        {
          'name': 'Broccoli',
          'type': 'Brassica'
        }];
        console.log('results', JSON.stringify(results));
        return results;
        };

But when i call the same JSON using $http.get it doesn't show results in autocomplete and nothing happends.

JavaScript
//RETURN: results [{"name":"Broccoli","type":"Brassica"}]
    $scope.getInterest2 = function() {
      $http.get("../inc/users/search_interest.php?query=" + $scope.searchText)
        .success(function(results) {
          //$scope.interest = results;
          console.log('results', JSON.stringify(results));
          return results.data;
        });
    };

But i can see in console that results are equals.

In my php file (which is called by $http.get) i return JSON with json-encode:

PHP
$row_set = array('name' => 'Broccoli', 'type'=> 'Brassica');
echo json_encode(array($row_set));

Maybe php json_encode return a bad formed json?

Thanks
Posted

1 solution

Hi,

Have you tried to return just results instead results.data;

Regards,
Roshan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900