dtutlamjasblef7982 2015-11-25 06:16
浏览 46
已采纳

从Angular Controller中的php文件中获取JSONP数据

Recently, I began to study Angular. So much I do not know. I'm trying to get json data from a php file to use within an Angular controller. But the data from php file does not exceed.

controllers.js:

app.controller('MainCtrl',['$scope', '$resource', '$http',
function($scope, $resource,$http) {
    $http.get('/xbmc.php').success(function(data) {
        $scope.data = data;
    });
}]);

xbmc.php:

    <?
include('sys/inc/config.inc.php');
include(SMARTY_DIR.'Smarty.class.php');
include(BASE_DIR .'sys/inc/classes.inc.php');
include(BASE_DIR .'sys/inc/init.inc.php');
include(BASE_DIR .'xbmcApi.php');
$jsonData = new xbmcApi($_GET['action']);
/**
if (MEGAKINO_LOGED)
{
**/
    $json = $jsonData->getResult();
/**
}
else 
    $json = array('authStatus' => '0');
**/     
echo json_encode($json);
?>

index.html:

<body ng-controller="MainCtrl">
    <div class="wrapper">
        <h2>{{title}}</h2>
        <div class="row">
            <div class="col-md-1 col-sm-2 col-xs-4" style="margin-top: 0.5%;" ng-repeat="item in data.items">
                <div class="image" style="margin-bottom: 1%">
                    <a data-ng-href="#!/seasons/serie/{{item.id}}">
                        <img data-ng-src="/files/series/thumb-{{item.id}}.jpg" alt=""/>
                    </a>
                </div>
                <div class="info">
                    <a data-ng-href="#!/seasons/serie/{{item.id}}">
                        <b>{{item}}</b>
                        <u>Рейтинг: {{item.rate}}</u>
                    </a>
                </div>
            </div>
        </div>
    </div>
</body>
  • 写回答

2条回答 默认 最新

  • dongshan3806 2015-11-25 06:36
    关注

    Your php code tells that your json will be build if a $_GET['action'] param is passed:

    $jsonData = new xbmcApi($_GET['action']);
    

    Yet, you are not passing any data as a query string from your angular controller. Try something like:

    app.controller('MainCtrl',['$scope', '$resource', '$http',
    function($scope, $resource,$http) {
        $http({
            url: '/xbmc.php', 
            method: "GET",
            params: {action: 'some_action'}
         }).success(function(data) {
            $scope.data = data;
        });
    }]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器