2010-06-16 42 views
1

我試圖從MySQL數據庫顯示我的事件。我正在使用事件功能。我返回的XML文件非常基礎。我查看了所有FullCalendar問題,其中大部分都討論JSON並指向JSON的文檔。我無法使用JSON。我必須去XML。你能告訴我我在哪裏嗎?FullCalendar和事件:函數

這裏是什麼我的XML看起來像一個示例:

<id><id> 
<title>Grow Your Business on the Web</title> <br> 
<start>2010-06-05T9:30</start> <br> 
<end>2010-06-05T12:30</end> <br> 
<className>O</className> <br> 
<url></url> 

整個文件是以一<event>標籤,並用</event>標籤關閉。

我jQuery是如下:

$(document).ready(function() { 

    $('#calendar').fullCalendar({ 
    height: 550, 
    theme: true, 
    header: { 
      left: 'prev,next today', 
     center: 'title', 
     right: 'month,agendaWeek,agendaDay' 
     }, 
    editable: true, 
    events: function(start, end, callback) { 

    $.ajax({ 
     url: 'ncludeFiles/sbdp-cal-xml.php', 
     dataType: 'xml', 
     data: { 
     // our hypothetical feed requires UNIX timestamps 
     start: Math.round(start.getTime()/1000), 
     end: Math.round(end.getTime()/1000) 
     }, 
     success: function(doc) { 

     var events = []; 

      $(doc).find('event').each(function() { 
       events.push({ 
        title: $(this).attr('title'), 
        start: $(this).attr('start'), 
        end: $(this).attr('end'), 
        className: $(this).attr('className'), 
        url: $(this).attr('url') 
       }); 
      }); 

      callback(events); 
     } 
    }); 
     } 
    }); 
}); 

我會很感激任何幫助,您可以給我。謝謝!

回答

0

示例代碼也不適用於我。試試這個:

$.ajax({ 
url: 'pathto/myxmlfeed.php', 
data: "start="+Math.round(start.getTime()/1000)+"&end="+Math.round(end.getTime()/1000)+"&_rand="+Math.floor(Math.random()*100), 
success: function(doc) { 
    var events = []; 
    $(doc).find('event').each(function() { 
     events.push({ 
     title: $(this).attr('title'), 
     url: $(this).attr('url'), 
     start: $(this).attr('start') // will be parsed 
     }); 

     }); 

     callback(events); 
    } 
    }); 

在您myxmlfeed.php你可以做一個$ _GET拉開始日期和結束日期查詢您的數據庫時使用。該XML的結構應該是這樣的:

<xml> 
<event id="1" title="first entry" url="http://www.google.com" start="2010-07-22" /> 
</xml> 

你還需要到的jquery.js更改爲1.3.2版本,1.4.2不正確的IE8工作。

0

上面的代碼給了我錯誤,因爲「回調不是一個函數」。
我換成這行 -

events: function(start, end, callback) { 

events: function(start, end, timezone, callback) { 

它開始工作。