ci中用easyui的问题,CRUD操作,取后台数据失败
测试用的是easyui官方提供的CRUD的demo在view中加载url:
<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()
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的分析可以知道后台的数据已经到达前台了。感觉成功已经近在咫尺,可是就是不知道问题在哪里。
大侠给点建议,我应该从哪里找问题。
哥来告诉你,这个问题哥也刚解决,被困扰了几天了。
首先你的数据格式是要这样的,要有方括号括起来,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就能读取了。 url="<?php echo site_url('space/easyui');?>"method="post"
得加个method上去,要不它更本不知道你url以什么方式提交过去。
页:
[1]