0

ここで、テーブル クエリの結果を表示する方法について少しだけ助けが必要です。ajax からの応答を確認すると、次のように表示されます。しかし、ビューに渡すと表示されません。これが私のコードです:

コントローラー/user.php

        <?php

        class User extends CI_Controller{

            public function __construct(){
                parent::__construct();
                $this->load->model('user_model');
            }

            public function index(){
                $this->load->view( 'index' );
            }

            public function read() {
                echo json_encode( $this->user_model->getAll() );
            }


        }

    ?>

モデル/user_model.php

        <?php

        class User_Model extends CI_Model{

            public function __construct(){
                parent::__construct();
            }

            public function getAll(){

                $qGetAllData = $this->db->get('user');
                if($qGetAllData->num_rows() > 0){
                    return $qGetAllData->result();
                }else{
                    return array();
                }

            }

        }

    ?>

    View/index.php

        <html>
      <head>
        <title><?php echo $title; ?></title>
        <base href="<?php echo base_url(); ?>" />
        <link type="text/css" rel="stylesheet" href="css/smoothness/jquery-ui-1.8.2.custom.css" />
        <link type="text/css" rel="stylesheet" href="css/styles.css" />
      </head>

      <body>

        <table id="records"></table>

        <div id="tabs">

          <ul>
            <li><a href="#read">Read</a></li>
            <li><a href="#create">Create</a></li>
          </ul>

          <div id="read">
            <table id="records"></table>
          </div>

          <div id="create"></div>

        </div>




        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-templ.js"></script>

        <script type="text/template" id="readTemplate">
          <tr>
            <td>${id}</td>                  //doesn't display ID
            <td>${name}</td>                //doesn't display Name
            <td>${email}</td>               //doesn't display EMial
          </tr>
        </script>

        <script type="text/javascript" src="js/myjs.js"></script>

      </body>

    </html>

JavaScript/myjs.js

            $(document).ready(function(){

        $( '#tabs' ).tabs({
                fx: { height: 'toggle', opacity: 'toggle' }
            });

            $.ajax({
                url: 'index.php/user/read',
                datatype: 'json',
                success: function(response){
                    $('#readTemplate').render(response).appendTo('#records');
                }
            });

        });

それはすべての人です。どこにエラーがあるのか​​ わかりません。

4

1 に答える 1