简体   繁体   English

ajax 成功并加载特定的 div 后内容消失了

[英]After ajax success and load specific div the content disappeared

I am making an event calendar.我正在制作活动日历。 After adding an event, only the cells of the calendar will be load after insertion of the data is successful.添加事件后,插入数据成功后,只会加载日历的单元格。 Adding event is fine but when div loaded the content disappear.添加事件很好但是当 div 加载时内容消失。 Here's my code:这是我的代码:

* Ajax * *阿贾克斯*

$('.savedata').on('click', function () {
                // alert('savedata');
                var testchecked = $('#testchecked').val();
                var testingcheck = $('#testingcheck').val();
                $.ajax({
                    type : "POST",
                    url  : "<?php echo site_url()?>/CalendarController/savedata",
                    // dataType : "JSON",
                    data : { testchecked : testchecked, testingcheck : testingcheck },
                    success: function(data){
                        // alert('success');
                        //console.log('asd '+data);

                        $('#events-modal').modal('hide');
                        // cal-month-box
                        // $(".cal-month-day").append(JSON.stringify(data));
                        // $(".cal-month-day").load(window.location + " .cal-month-day");
                        // $('.cal-month-day').prepend(_newData);
                        $(".cal-month-day").load(location.href + " .cal-month-day");
                    },
                    error : function(data, ajaxOptions, thrownError) {
                        console.log(data.status);
                    }
                    });
                });

* Before adding data * * 添加数据之前 *

在此处输入图像描述

* after adding event * * 添加事件后 *

在此处输入图像描述

* Here's the HTML * * 这是 HTML *

在此处输入图像描述

* Controller * * 控制器 *

public function savedata()
    {
        $this->load->view('calendarView');

        $this->em->form_insert();

    }

* Model * * 模型 *

function form_insert()
    {
        $abc            = $this->input->post('testchecked');

        $array = array('id' => $abc);
        $this->db->select("*");
        $this->db->where($array);
        $query = $this->db->get('dev_adkt_events_type');
        $response = $query->result_array();
        foreach($response as $res){
            $title = $res['id'];
        }


        $url            = 'URL';
        $class          = $this->input->post('testchecked');
        $start_date     = $this->input->post('testingcheck');
        $end_date       = $this->input->post('testingcheck');

        $data = array(
            'title'     => $title,
            'url'       => $url,
            'class'     => $class,
            'start_date'=> $start_date ,
            'end_date'  => $end_date 
        );

        // $this->db->insert('event',$data);
        $result = $this->db->insert('event',$data);
        return $result;

    }

Hope you could help me guys.希望你们能帮助我。 Thank you in advance.先感谢您。

* Displaying the Calendar * * 显示日历 *

Controller控制器

public function index() {
        $this->load->helper('url');
        // var_dump($postData);
        $result['eventcatresult'] = $this->em->geteventcategory();
        $result['data'] = $this->em->getevent();
        $result['data'] = $this->em->getnotes();

        $this->load->view('calendarView',$result);
    }

* Model * * 模型 *

function getevent()
    {
        $this->db->select("*");
        $query = $this->db->get($this->event);
        if ($query) {
            return $query->result();
        }
        return NULL;
    }

you better change this你最好改变这个

$(".cal-month-day").load(location.href + " .cal-month-day");

to this对此

$("#calendar").load(location.href + " #calendar");

because you have multiple 'cal-month-day' for every event and if the last element empty your all elements will be empty因为每个事件都有多个'cal-month-day' ,如果最后一个元素为空,则所有元素都将为空
better refresh all calendar最好刷新所有日历

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM