簡體   English   中英

在Codeigniter中使用angular js獲取數據庫記錄

[英]fetching DB record using angular js in codeigniter

請幫助我在Angular JS中新嘗試執行插入操作,現在嘗試檢索數據,我只是搞砸了。 沒有收到任何錯誤,但我的表在瀏覽器中為空。 控制台中也沒有錯誤。 現在需要更改或更新什么? 我分享了我的代碼,請查看並幫助我。

App.js:

var myapp = angular.module('myApp', []);
(function(app)
{
    myapp.controller("ViewController", ['$scope','$http', function($scope, $http ) 
    {
        $scope.results = [];
        $http({
            method: 'GET',
            url:'http://localhost/ngci/user/view'
        }).then(function (data, status) 
        {
            $scope.results = data;
        });
    }]);
})(myapp);

控制器:

 public function view()
 {
    $data['x'] = $this->user_model->viewusers();

    $this->load->view('view_data',$data);
 }

視圖:

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>angular/app.js"></script>
</head>
<body>

<div id="container" ng-app="myApp" ng-controller="ViewController">
<table class="table table-bordered"> 
<thead>
    <th>name </th>
    <th>city</th>
</thead>
<tbody>
    <tr ng-repeat="x in results">
        <td>{{ x.name }}</td>
        <td>{{ x.city }}</td>
    </tr>
</tbody>
</table>
</div>
</body>
</html>

不是有經驗的專家,而是嘗試以JSON formate發送數據。 這是控制器代碼:

public function view() {
    $data = $this->user_model->viewusers();     
    $this->output->set_content_type('application/json')->set_output(json_encode($data));
}

看到這個例子鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM