angular代码差错

控制器代码如下


var myapp1 = angular.module('myApp', []);
  myapp1.controller('wyCtrl', ['$scope','$http',function($scope,$http) {
    $http({
      method:'get',
      url:'/php/search.php'
    }).then(function(response){
      //成功时执行
      console.log(response);
      $scope.items = response.items;
    },function(response){
      //失败时执行
      console.log(response);
    });
}]);

HTML代码如下

        <div ng-controller="wyCtrl" >
                                <ol style="float:left;text-align:left">
                                    <li ng-repeat="x in items">
                                        <div style="font-size:20px;line-height:40px;  ">
                                            {{x.title}}
                                        </div>
                                    </li>
                                </ol>
                                <ul style="float:right;">
                                    <li ng-repeat="x in items" style="list-style-type:none;line-height:40px ">
                                        {{x.time}}
                                    </li>
                                </ul>
                                <script src="namesController.js"></script>
                            </div>

php代码

<?php
$items = [
  ['title' => 'tyz' , 'time' => 'www.baidu.com'],
  ['title' => 'zyt' ,  'time' => 'www.qq.com'],
];
echo json_encode($data,JSON_UNESCAPED_UNICODE);
?>

控制台輸出Cannot read property '1' of null

页面无法显示内容,另外请问如何修改以上代码才能使得前端向php传递参数

阅读 1.8k
1 个回答

控制台输出的什么?你查看一下Network看看返回了什么数据,应该是在response.data中。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题