Php codeigniter ajax加载表
我已经写了一些codeigniter代码,当我点击按钮添加数据时,表将重新加载,而不是重新加载页面。如何修改我的代码?谢谢 这是我的控制器Php codeigniter ajax加载表,php,codeigniter,Php,Codeigniter,我已经写了一些codeigniter代码,当我点击按钮添加数据时,表将重新加载,而不是重新加载页面。如何修改我的代码?谢谢 这是我的控制器 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Big_category extends CI_Controller { function __construct() { ... } function index
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Big_category extends CI_Controller {
function __construct() {
...
}
function index() {
if($this->session->userdata('logged_in')) {
$this->page(0);
} else {
show_404('page');
}
}
function page($page) {
....
$data['pagelist']=$this->pagination->create_links();
$data["main_content"] = "big_category_view";
$this->load->view('template', $data);
}
这是我的看法
...
<? $data = json_decode($all_big_category); ?>
<? foreach($data as $key => $value): ?>
<tr class="modify_tr">
<td><?=($key+1)?></td>
<td id="td_id_<?=$value->c1_id?>" class="modify_td">
<span id="c1_id_<?=$value->c1_id?>"><?=$value->c1_name?></span>
<form class="form-search td_id_<?=$value->c1_id?>">
<input type="text" name="input_c1_id" id="input_c1_id_<?=$value->c1_id?>">
<button class="btn modify" id="button_c1_id_<?=$value->c1_id?>" c1-id="<?=$value->c1_id?>" type="button"><i class="icon-edit"></i></button></td>
</form>
<td><button class="btn btn-danger"><i class="icon-remove-sign"></i></button></td>
</tr>
<? endforeach ?>
</table>
<?=$pagelist?>
...
。。。
下面是一个简单的技巧,说明如何实现这一点
布局(模板)
JQuery
$.ajax({
type : 'POST',
url : '<?php echo site_url('controllername/index')?>',
data : '' // query string
success : function(formagain){
$('#form_id').html(formagain);
//this will replace the content of div with new form
}
});
$.ajax({
键入:“POST”,
url:“”,
数据:“”//查询字符串
成功:功能(形式增益){
$('form#id').html(formagain);
//这将用新表单替换div的内容
}
});
以下是一个简单的技巧,可以帮助您实现这一点
布局(模板)
JQuery
$.ajax({
type : 'POST',
url : '<?php echo site_url('controllername/index')?>',
data : '' // query string
success : function(formagain){
$('#form_id').html(formagain);
//this will replace the content of div with new form
}
});
$.ajax({
键入:“POST”,
url:“”,
数据:“”//查询字符串
成功:功能(形式增益){
$('form#id').html(formagain);
//这将用新表单替换div的内容
}
});
什么不起作用?你的ajax电话在哪里?与现在发生的事情相比,您期望的结果是什么?视图需要编写一些表代码,如果我想使用ajax load table,我应该再次编写此代码?我想把视图代码变成一个模板,数据会填入这个表格,我不知道,你能给我几点指点吗?谢谢什么坏了?你的ajax电话在哪里?与现在发生的事情相比,您期望的结果是什么?视图需要编写一些表代码,如果我想使用ajax load table,我应该再次编写此代码?我想把视图代码变成一个模板,数据会填入这个表格,我不知道,你能给我几点指点吗?ThanksI有一个疑问,ajax的$data,我会使用一个lof字符串来构建一个表单?(比如:var str=“…”)。谢谢。@Lighter用html编写php不是一个好的实践,当CI提供独立的视图时,我们为什么不使用它呢?我有一个疑问,ajax的$data,我会使用lof字符串来构建表单?(比如:var str=“…”)。谢谢。@用html编写php不是一个好的实践,当CI提供独立视图时,我们为什么不使用它呢?
function index()
{
if($this->input->is_ajax_request()){
//load form here
$this->load->view('form');
}else{
//this will load the form for the first time
//pass third parameter as TRUE so it will returned as string
//assigned to index content which will be displayed in layout
$data['content'] = $this->load->view('form',$data , TRUE);
//load template here
$this->load->view('template', $data);
}
}
$.ajax({
type : 'POST',
url : '<?php echo site_url('controllername/index')?>',
data : '' // query string
success : function(formagain){
$('#form_id').html(formagain);
//this will replace the content of div with new form
}
});