我正在使用Ajax将数据存储到数据库中,并且我在控制器函数中加载了两个视图。现在,作为回应,我得到了两个观点的两个内容。谁能告诉我怎么能把这两个div分开?
我的ajax代码是folows:
$.ajax({
url:base_url+'welcome/add_group_to_archieve',
type:'post',
data:data,
success:function(response){
$(".group_value").html(response);
alert(response);
get_groups_list();
$(".archieves_list").html(response);
},
error:function(){
alert('ajax failure');
}
});
控制器:
public function add_group_to_archieve() {
$user_id = $this->tank_auth->get_user_id();
$archieve_selected = $this->input->post('archieve_selected');
$this->s_model->insert_as_archieve($archieve_selected);
$data['get_archieved_groups'] = $this->s_model->get_archieved_groups();
$data['retrieved_group_values'] = $this->s_model->retrieve_group_post();
$data['file_id'] = $this->s_model->get_profile_picture($user_id);
$data['edited_content'] = $this->s_model->get_save($user_id);
$this->load->view('ajax_response_archieved_groups_list', $data);
$this->load->view('ajax_response_archieved_groups_select', $data);
}
模型:
function get_archieved_groups() {
$this->db->select('*');
$this->db->where('archieved', 'archieved');
$data = $this->db->get('groups');
return $data->result();
}
DIV1:
<div class="archieves clearfix" id="ajax_response_archieved_groups_list">
<div class="archieves_list">
<h6>Archieved Group Tags</h6>
<? //php echo '<pre>'; print_r($get_archieved_groups[0]); echo '</pre>'; exit; ?>
<ul><?php
if (isset($get_archieved_groups)) {
foreach ($get_archieved_groups as $row) {
?>
<li><?php if (isset($row->group_name)) { ?><?php
echo $row->group_name;
}
?></li>
<?
}
}
?>
</ul>
</div>
</div>
DIV2:
<div class="creating archieves" id="ajax_response_archieved_groups_select1">
<select id="archieves_select_box">
<option value="<?php echo "All"; ?>"><?php echo "All"; ?></option>
<?php foreach ($get_archieved_groups as $row) { ?>
<option value="<?php echo $row->group_name; ?>"><?php echo $row->group_name; ?></option>
<?php } ?>
</select>
</div>
答案 0 :(得分:0)
知道了,只需要两个单独的函数来加载不同的视图并调用两个不同的ajax响应。 以下是我的ajax代码:
$.ajax({
url:base_url+'welcome/add_group_to_archieve',
type:'post',
data:data,
success:function(response){
$(".group_value").html(response);
alert(response);
get_groups_list();
$(".archieves_list").html(response);
archieved_select();
},
error:function(){
alert('ajax failure');
}
});
function archieved_select(){
$.ajax({
url:base_url+'welcome/add_group_to_archieve_select',
type:'post',
data:data,
success:function(response){
$("#ajax_response_archieved_groups_select1").html(response);
},
error:function(){
alert('ajax failure');
}
});