Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
 
If you have no copy errors in your JSON, the it is indeed invalid. It should be [{...},{...},...]. I.e. brackets around the objects and commas between them. –  Nikos Paraskevopoulos Sep 16 at 9:44
 
$scope.rdpDate = {'test': [Rdpservice2.query()]}; it still get nothing ? –  user2783402 Sep 16 at 9:49
 
The JSON output you've pasted is not from json_encode( $rows );; where does it come from? –  feeela Sep 16 at 9:50
 
sorry , I can't understand it, would you say more detail? –  user2783402 Sep 16 at 9:54

1 Answer

up vote 1 down vote accepted

Rdpservice2.query() expects an array.

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

share|improve this answer
 
thanks for your help ! –  user2783402 Sep 16 at 10:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.