0

我正在使用 Ajax 将数据存储到数据库中,并且我在控制器函数中加载了两个视图。现在,作为回应,我得到了两个视图的两个内容。谁能告诉我如何将两个 div 分开?

我的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);
        },
        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>
4

1 回答 1

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');
}    
});
于 2013-02-14T11:02:14.023 回答