2017-06-21 79 views
0

我想實現什麼? - >我需要從sql中追加值標題和url。如何從php獲取數據並將其傳遞到另一個oojs

$('#calendar').fullCalendar({ 
     defaultDate: '2017-06-12', 
     editable: true, 
     eventLimit: true, // allow "more" link when too many events 
     events: [ 

    { 
    "title": "Click for Google", 
    "url": "http://google.com/", 
    "start": "2017-06-28" 
    }] 

我試過了嗎? - >

$.ajax({ 
    type: 'GET', 
    url: 'eventcalendar.php', 

    dataType:'JSON', 
    success: function(response) { 
    console.log(response[0]); 
    return response; 
    } 
}); 

我得到了什麼? - >

{"title":"Example","start":"2017-06-21","end":"2017-06- 
    22","url":"http:\/\/www.facebook.com"}{"title":"Holiday","start":"2017-06- 
    23","end":"2017-06-24","url":"http:\/\/www.google.com"} 

我的PHP代碼: - >

  <?php 
     error_reporting(0); 
     include 'announcements/db.php'; 

     $sql = mysql_query("select title, start, end, url from eventcalendar"); 
     $num_rows = mysql_num_rows($sql); 
     $userinfo = array(); 

     while ($row_user = mysql_fetch_assoc($sql)) { 
      $userinfo[] = $row_user; 

        } 
     echo json_encode($userinfo); 
     ?> 

我需要從MySQL獲得的價值和更新的事件中:使從SQL所有的標題標籤會顯示

*我是一個新手,這是我的第一個代碼。如果您有更好的選擇,請提供幫助和建議。萬分感謝 !!

+0

*我是一個新手,這是我的第一個代碼*瀏覽PHP手冊,那麼你將瞭解到'mysql_ *'函數已折舊並不再受支持 –

+0

@MasivuyeCokile感謝您的信息。你能幫助上面的代碼嗎? –

回答

0

我假設您使用的是FullCalendar庫。

除了不推薦使用的mysql_ *函數,我認爲你對ajax的用法有些困惑。

成功函數只有在ajax解析並且響應成功時纔會觸發。所以,你可以考慮兩種不同的方法是:

1 - 初始化您的日曆,當您收到響應數據:

$.ajax({ 
    type: 'GET', 
    url: 'eventcalendar.php', 
    dataType:'JSON', 
    success: function (response) { 
     $('#calendar').fullCalendar({ 
      defaultDate: '2017-06-12', 
      editable: true, 
      eventLimit: true, 
      events: response 
     }); 
    } 
}); 

2 - 刷新日曆事件當AJAX解決。在這種情況下,你可以使用FullCalendar內置的方法:

success: function (response) { 
    $('#calendar').fullCalendar('updateEvents', response); 
} 

希望我幫助,祝你好運:)

+0

非常感謝。像魅力一樣工作..你是對的。我對此感到困惑不已。感謝您的注意和解釋... –

相關問題