使用php在fullcalendar中实现ajax调用

时间:2015-02-15 11:16:36

标签: php ajax fullcalendar pyrocms

我已经在php中实现了完整的calenedar。它工作正常。我已经从数据库调用了数据并在fullcalendar中显示了它。 现在我已经实现了一个下拉列表。我用ajax调用控制器调用我的另一个视图。 控制器根据下拉选择获取数据。默认情况下,它会获取所有数据。 但是我在ajax通话后没有得到日历。我已调用脚本在ajax视图中加载完整日历。 当我在ajax视图页面中回显时,我得到了所需的数据。但是在ajax调用之后我无法显示完整的日历。

如我所知,我已经提供了代码。

我的第一个观点:

<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.print.css" rel="stylesheet" media="print" />
<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.css" rel="stylesheet" />

<div class="content">
    <div id='input'>
        <?php echo form_dropdown("package_id", $packagelist, "",'id="packageid"'); ?>
    </div>
    <div id='calendar'></div>
</div>

<style>
    #calendar {
        max-width: 900px;
        margin: 0 auto;
    }
</style>
<script type="text/javascript">
    $(document).ready(function() {
        $('#packageid').change(function() { //any select change on the dropdown with id country trigger this code           
            var packageid = $('#packageid').val();
           alert(packageid);

            $.ajax({
                type: "POST",
                url: "<?php echo base_url('admin/schedule/scheduledetails/hel') ?>", //here we are calling our user controller and get_cities method with the country_id
                data: {'packageid': packageid,},
                success: function(data)
                {  


                },
                error: function() {
                    alert('failed');
                }
            });



        });
    });

</script>

<script>

    $(document).ready(function() {       

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            displayEventEnd: {
                month: true,
                basicWeek: true,
                "default": true
            },
            defaultDate: '2014-11-12',
            //editable: true,
            eventLimit: true, // allow "more" link when too many events

            events: 
            "<?php echo base_url('admin/schedule/scheduledetails/json');?>",
        });

    });

</script>

我的控制器hel函数

 public function hel()
{ 
    $packageid = 9;//$_POST['packageid']; 

//   echo "hello";
   $coursedetails = $this->course_m->where('course_id',$packageid)->get_all();
  // echo "<pre>";print_r($coursedetails); echo "</pre>";
    $scheduledetails = array();
        foreach ($coursedetails as $details) {

            $packagedays = $this->course_m->packagedays($details->id);
            $presentdays = $this->attendance_m->count_attendance($details->id);

            $startdate = $details->start_date;
            $starttime = $details->start_time;
            $endtime = $details->end_time;
            $postponedays = 0;
            //$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));

            $postponedays = $this->postpone_m->count_postponedays($details->id);
            if ($postponedays == 0) {
                $enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));
            } else {
                $add = $postponedays + $packagedays;
                $enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $add . ' days'));
                $postponefrom = $this->postpone_m->postponedate($details->id)->postponefrom;
                $postponeto = $this->postpone_m->postponedate($details->id)->postponeto;
                //echo $postponeto;die;
            }

            $temp = array
                (
                array
                    (
                    'course_id' => $details->id, //it means acutal course id
                    'title' => $this->training_package_m->get($details->course_id)->training_code, //course_id means packageid                    
                    'start' => $startdate . 'T' . $starttime,
                    'end' => $enddate . 'T' . $endtime,
                    'description' => 'Hello gyys how are you all',
                    'starttime' => $starttime,
                    'endtime' => $endtime,
                   // 'postponefrom' => $postponefrom,
                    //'postponeto' => $postponeto,
                    'postponeddays' => $postponedays,
                    'packagedays' => $packagedays,                
                    ),
                );
            $scheduledetails = array_merge($scheduledetails, $temp);
        }
        // echo json_encode($scheduledetails); 

          $data['jsondata'] = json_encode($scheduledetails);

          //print_r($data['jsondata']);die;
           $this->template
               ->title($this->module_details['name'])                
                ->set_layout(false)
                ->build('admin/fullcalendarfiltered',$data);             


}

我通过控制器加载的视图。即fullcalendarfiltered视图文件

<style>
    #calendar {
        max-width: 900px;
        margin: 0 auto;
    }
</style> 
<div>Test Ajax</div>
 <div id='calendar'></div>
<script>
   $(document).ready(function() {       

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            displayEventEnd: {
                month: true,
                basicWeek: true,
                "default": true
            },
            defaultDate: '2014-11-22',
            //editable: true,
            eventLimit: true, // allow "more" link when too many events

            events: "<?= $jsondata?>",
        });

    });
</script>

视图文件仅显示测试ajax。当我回显视图文件中的json数据时,它会被回显。但问题是它不会在日历中加载。事实上,日历不会显示在fullcalendarfiltered视图文件

0 个答案:

没有答案