1
我正在codeignitor.I工作,想从php控制器返回表并希望在角度js控制器中访问它。 这里是php控制器的代码。 Table.php如何在角度js控制器中访问从php控制器中的表或变量
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Table extends CI_Controller {
public function index(){
$this->load->view('home');
}
public function live()
{
$data=" .<table><tbody><tr> <th> a </th><th> b</th><th> c </th>."
".</tr><tr<td>1</td><td>2</td><td>3</td></tr> </tbody></table> .";
or
$data="one";
return $data;
}
}
下面是具有控制器的route.js的代码。
var myApp = angular.module('myapp', ['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('home',{
url: '/',
templateUrl: 'home.html',
// controller: 'mainctrl'
})
.state('live',{
url:'/live',
templateUrl: 'partials/show.html',
controller: 'livectrl'
})
});
myApp.controller('livectrl',function($scope,$http,$location,$state){
$http.get('/live').success(function(res){
$scope.items=res;
console.log($scope.items);
console.log("work");
$state.go('live');
}).
error(function(err){
alert(13);
})
});
这里是home.php
<html>
<head>
<script src="<?php echo base_url(); ?>libs/js/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
<script src="<?php echo base_url(); ?>libs/js/route.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="livectrl">
<div ui-view=""></div>
</div>
</body>
</html>
我列出的“本地主机/ tcric”应用程序代码时livectrl被称为它返回错误警报“13”。 如何从php控制器返回数据并在角度js控制器中访问它。