用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5457|回复: 2
收起左侧

ci中用easyui的问题,CRUD操作,取后台数据失败

[复制链接]
发表于 2013-5-25 00:07:48 | 显示全部楼层 |阅读模式
测试用的是easyui官方提供的CRUD的demo

在view中加载url:
HTML复制代码
    <table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"  url="<?php echo site_url('space/easyui');?>"              toolbar="#toolbar" pagination="true"  
            rownumbers="true" fitColumns="true" singleSelect="true">  
        <thead>  
            <tr>  
                <th field="firstname" width="50">First Name</th>  
                <th field="lastname" width="50">Last Name</th>  
                <th field="phone" width="50">Phone</th>  
                <th field="email" width="50">Email</th>  
            </tr>
复制代码

无法加载后台的信息。用firebug查看有响应,是一串json格式的数据:
{"id":"1","firstname":"11","lastname":"12","phone":"1233333","email":"1@1.com"}
直接访问方法‘space/easyui’也是有响应的,也是{"id":"1","firstname":"11","lastname":"12","phone":"1233333","email":"1@1.com"}

space控制器中的方法easyui()
PHP复制代码
                public function easyui()                {
                        $this->load->helper('url');
                       
                       
                        $data = array(
                        'id' =>'1',
                        'firstname' =>'11',
                        'lastname' => '12',
                        'phone' => '1233333',
                        'email' => '1@1.com'
                        );
                        $this->output->append_output(json_encode($data));
                }
复制代码


通过firebug的分析可以知道后台的数据已经到达前台了。感觉成功已经近在咫尺,可是就是不知道问题在哪里。
大侠给点建议,我应该从哪里找问题。
发表于 2013-7-23 23:47:32 | 显示全部楼层
哥来告诉你,这个问题哥也刚解决,被困扰了几天了。
首先你的数据格式是要这样的,要有方括号括起来,easyui才能读取数据,不然根本就是格式不对无法读取。
[{"id":"10001","firstname":"zhong","lastname":"ren","phone":"178484554048","email":"qq.com}]

那要怎么构造这样的格式呢,用二维数组来转换了。下面看代码

echo json_encode(
    array(   
    0=> array(    'id' => '10001',   
         'firstname' => 'zhong',   
         'lastname' => 'ren',   
         'phone' => '178484554048',   
         'email' => 'qq.com')
   ));

这样用echo输出转换好的json数据,easyui就能读取了。
发表于 2013-9-17 09:15:58 | 显示全部楼层
url="<?php echo site_url('space/easyui');?>"  method="post"

得加个method上去,要不它更本不知道你url以什么方式提交过去。

本版积分规则