gpt4 book ai didi

javascript - php返回带有angularjs错误的json

转载 作者:行者123 更新时间:2023-11-30 05:44:18 26 4
gpt4 key购买 nike

我是 php 和 angularjs 的新手,

我有php代码,它可以像这样返回json数据

{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 代码

<?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);

?>

我想获取 Angular 范围内的数据

Angularjs 代码

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


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

错误信息

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

但是 $scope.rdpData 获取不到任何数据?

我很困惑,请帮忙

最佳答案

Rdpservice2.query() 需要一个数组。

尝试将 isArray = True 添加到 {method: 'GET'}也就是说,{method: 'GET', isArray: true}

关于javascript - php返回带有angularjs错误的json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com