FullCalendar:尝试使用json文件显示事件时收到错误

时间:2015-05-13 02:21:28

标签: javascript php json fullcalendar

以下是我的JSON文件:

<?php
              $driver_booking = q("select * from vehicle_driver_booking where vehicle_id = ".$_REQUEST['ch']);
              $array = array();
              foreach($driver_booking as $bookings) {
                  $driver = getRow("vehicle_driver", $bookings['driver_id']);
                  //return date_time from only....
                  $date_from = date("Y-m-d",$bookings['datetime_from']);
                  $time_from = date("H:i:s",$bookings['datetime_from']);
                  //return date_time to only.....
                  $date_to = date("Y-m-d",$bookings['datetime_to']);
                  $time_to = date("H:i:s",$bookings['datetime_to']);
                  if($bookings['days_option'] == 1) {
                      $start = $date_from."T".$time_from;
                      $array[] = array('id' => $bookings['id'], 'title' => $driver['name'], 'start' => $start, 'allDay' => false);
                  } else {
                      $start = $date_from."T".$time_from;
                      $end = $date_to."T".$time_to;
                      $array[] = array('id' => $bookings['id'], 'title' => $driver['name'], 'start' => $start, 'end' => $end, 'allDay' => false);
                  }

              }

              echo json_encode($array);
          ?>

以下是日历的一部分,我试图从上面的文件中获取json数据。

eventSources: [

    // your event source
    {
        url: '/vehicle_json.php',
        type: 'POST',
        data: {
           // custom_param1: 'something',
            //custom_param2: 'somethingelse'
        },
        error: function() {
            alert('there was an error while fetching events!');
        },
        color: 'yellow',   // a non-ajax option
        textColor: 'black' // a non-ajax option
    }

    // any other sources...

],

或者我也尝试过以下这种方式......但是没有工作,上面给了我警示信息,然后根本不给我任何东西。

events: 'vehicle_json.php',

&安培;一旦上述问题将解决,那么我也想通过使用以下内容更新我的事件,当记录保存它时刷新事件以显示更新事件。

$.ajax({
    url: "save_booking_details.php",
    type: "POST",
    data: {booking_id: bookingid, date_single: datesingle, date_from: datefrom, date_to: dateto},
    success: function(data){
        //alert(data);
        //location.reload();

        //$('#calendar').fullCalendar('removeEventSource', curSource[0]);
    //$('#calendar').fullCalendar('removeEventSource', curSource[0]);
    $('#calendar').fullCalendar('refetchEvents');
    //Calendar.init();
            //setTimeout(function(){ Calendar.init(); }, 10000);

    }, error: function() {
        alert("something went wrong!");
    }
});

所以有人可以帮忙,因为我正在寻找解决方案,因为昨天谢谢你们先进的。

1 个答案:

答案 0 :(得分:0)

您必须提供名为ch的参数。不确定它是什么

data: {
    'ch': "something I don't know"
},