user2783402
user2783402

Reputation: 63

php return json with angularjs error

I am new with php and angularjs ,

I have php code , it can return json data like this

{id:10, sessionName:99, computer:99, quality:LAN(very fast), networkAuthentication:Disable,…}
{id:13, sessionName:55, computer:55, quality:LAN(very fast), networkAuthentication:Disable,…}
{id:14, sessionName:bb, computer:bb, quality:LAN(very fast), networkAuthentication:Disable,…}   
{id:15, sessionName:77, computer:77, quality:LAN(very fast), networkAuthentication:Disable,…}
{id:16, sessionName:00, computer:00, quality:LAN(very fast), networkAuthentication:Disable,…}

PHP CODE

<?php
  include 'config_open_db.php';

  $sql= "select * from rdp";
  $sth = mysql_query($sql);
  $rows = array();
  while($r = mysql_fetch_assoc($sth)) {
    $rows[] = $r;
  }
  print json_encode($rows);

 ?>

I want get data with angular scope

Angularjs CODE

angular.module('remoteApp')
 .factory('Rdpservice2', function ($resource) {
return $resource('scripts/services/rdp2.php', {}, {
  query:  {method: 'GET'}
  });
});


$scope.rdpDate = {'test': Rdpservice2.query()};

ERROR MESSAGE

TypeError: Object #<Resource> has no method 'push'

but $scope.rdpData can't get any data?

I am so confused, please help

Upvotes: 2

Views: 907

Answers (1)

kubuntu
kubuntu

Reputation: 2535

Rdpservice2.query() expects an array.

Try adding isArray = True to {method: 'GET'} That is, {method: 'GET', isArray: true}

Upvotes: 1

Related Questions