2014-10-28 104 views
0

大家好我现在深化发展与规划模块 我使用Fullcalendar JS打造规划一些日历 一个应用程序,我发现这个代码Fullcalendar PHP MySQL的JSON

initCalendar: function() { 
      if (!jQuery().fullCalendar) { 
       return; 
      } 

      var date = new Date(); 
      var d = date.getDate(); 
      var m = date.getMonth(); 
      var y = date.getFullYear(); 

      var h = {}; 

      if ($('#calendar').width() <= 400) { 
       $('#calendar').addClass("mobile"); 
       h = { 
        left: 'title, prev, next', 
        center: '', 
        right: 'today,month,agendaWeek,agendaDay' 
       }; 
      } else { 
       $('#calendar').removeClass("mobile"); 
       if (App.isRTL()) { 
        h = { 
         right: 'title', 
         center: '', 
         left: 'prev,next,today,month,agendaWeek,agendaDay' 
        }; 
       } else { 
        h = { 
         left: 'title', 
         center: '', 
         right: 'prev,next,today,month,agendaWeek,agendaDay' 
        }; 
       }    
      } 

      $('#calendar').fullCalendar('destroy'); // destroy the calendar 
      $('#calendar').fullCalendar({ //re-initialize the calendar 
       disableDragging: false, 
       header: h, 
       editable: true, 
       events: [{ 
         title: 'All Day Event',       
         start: new Date(y, m, 1), 
         backgroundColor: App.getLayoutColorCode('yellow') 
        }, { 
         title: 'Long Event', 
         start: new Date(y, m, d - 5), 
         end: new Date(y, m, d - 2), 
         backgroundColor: App.getLayoutColorCode('green') 
        }, { 
         title: 'Repeating Event', 
         start: new Date(y, m, d - 3, 16, 0), 
         allDay: false, 
         backgroundColor: App.getLayoutColorCode('red') 
        }, { 
         title: 'Repeating Event', 
         start: new Date(y, m, d + 4, 16, 0), 
         allDay: false, 
         backgroundColor: App.getLayoutColorCode('green') 
        }, { 
         title: 'Meeting', 
         start: new Date(y, m, d, 10, 30), 
         allDay: false, 
        }, { 
         title: 'Lunch', 
         start: new Date(y, m, d, 12, 0), 
         end: new Date(y, m, d, 14, 0), 
         backgroundColor: App.getLayoutColorCode('grey'), 
         allDay: false, 
        }, { 
         title: 'Birthday Party', 
         start: new Date(y, m, d + 1, 19, 0), 
         end: new Date(y, m, d + 1, 22, 30), 
         backgroundColor: App.getLayoutColorCode('purple'), 
         allDay: false, 
        }, { 
         title: 'Click for Google', 
         start: new Date(y, m, 28), 
         end: new Date(y, m, 29), 
         backgroundColor: App.getLayoutColorCode('yellow'), 
         url: 'http://google.com/', 
        } 
       ] 
      }); 
     }, 

所以我做了一个PHP脚本返回的事件JSON格式

<?php 
require_once("inc/db_const.php"); 
try { 
    $connection= new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
    $query = "SELECT id,title,start,end FROM events"; 
    $sth = $connection->prepare($query); 
    $sth->execute(); 
    $events = array(); 
$sth->bind_result($id,$title,$start,$end); 
while($sth->fetch()) { 
     $e = array(); 
     $e['id'] = $id; 
     $e['title'] = "Lorem Ipsum"; 
     $e['start'] = $start; 
     $e['end'] =$end; 
     $e['allDay'] = false; 
     // Merge the event array into the return array 
     array_push($events, $e); 
    } 
    // Output json for our calendar 
    echo json_encode($events); 
    exit(); 

} catch (PDOException $e){ 
    echo $e->getMessage(); 
} 
?> 

谁能帮助我如何能fullcalnder的代码静态值的JSON retrun从PHP改变

+0

你想获得通过AJAX的JSON数据? – 2014-10-28 12:51:31

+0

是@Rik_s我这是我的问题 – EMIN 2014-10-28 12:52:27

回答

2

你的PHP脚本的URL就传递到事件参数,而不是事件数组:

 $('#calendar').fullCalendar({ //re-initialize the calendar 
      disableDragging: false, 
      header: h, 
      editable: true, 
      events: "/url/to/your/PHP/Script.php" 
     }); 

欲了解更多信息:http://fullcalendar.io/docs/event_data/events_json_feed/

+0

谢谢Ayem :) – EMIN 2014-10-28 13:47:35