2

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

4
  • 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. Commented Sep 16, 2013 at 9:44
  • $scope.rdpDate = {'test': [Rdpservice2.query()]}; it still get nothing ? Commented Sep 16, 2013 at 9:49
  • The JSON output you've pasted is not from json_encode( $rows );; where does it come from? Commented Sep 16, 2013 at 9:50
  • sorry , I can't understand it, would you say more detail? Commented Sep 16, 2013 at 9:54

1 Answer 1

1

Rdpservice2.query() expects an array.

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

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

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.