2016-05-27 24 views
0

Ich arbeite im vollen Kalender. Jetzt muss ich alle Ereignisse von der Datenbank durch den Ajaxaufruf zeigen. Bis jetzt habe ich die Ereignisse von der Datenbank durch json genommen. Mein json Ausgang ist wie nach dem Var_dump folgt:FullCalendar: wie Ereignisse im Vollkalender durch Ajax Antwort anzeigen

array (size=3) 
    0 => 
    array (size=7) 
     'title' => string 'hi' (length=2) 
     'id' => int 1 
     'start' => string '2016-05-30 00:00:00.000' (length=23) 
     'rendering' => string 'background' (length=10) 
     'backgroundColor' => string '#ff9999' (length=7) 
     'className' => string 'event-full' (length=10) 
     'textColor' => string 'white' (length=5) 
    1 => 
    array (size=7) 
     'title' => string 'vibrator' (length=8) 
     'id' => int 3 
     'start' => string '2016-05-26 00:00:00.000' (length=23) 
     'rendering' => string 'background' (length=10) 
     'backgroundColor' => string '#ff9999' (length=7) 
     'className' => string 'event-full' (length=10) 
     'textColor' => string 'white' (length=5) 
    2 => 
    array (size=7) 
     'title' => string 'vibrator' (length=8) 
     'id' => int 8 
     'start' => string '2016-05-26 00:00:00.000' (length=23) 
     'rendering' => string 'background' (length=10) 
     'backgroundColor' => string '#ff9999' (length=7) 
     'className' => string 'event-full' (length=10) 
     'textColor' => string 'white' (length=5) 

und mein Skript durch meine Ajax ist wie folgt: -

events: function(start, end, timezone, callback) 
{  
$.ajax({ 
     url: "calendar/show_events", 
     type: 'POST', // Send post data 
     data: 'type=fetch_events', 
     async: true, 

     success: function(s){ 

      dynamic_events =s; 
         alert(dynamic_events); 
      // $('#calendar').fullCalendar('addEventSource', JSON.parse(dynamic_events)); 

       var dynamic_events = []; 
       $(doc).find('event').each(function() { 
        events.push({ 
         title: $(this).attr('title'), 
         start: $(this).attr('start') // will be parsed 
        }); 
       }); 
       callback(events); 

       } 
    });  
} 

Was der Fehler in meinem Code ist .. Ich will jetzt erfahren, . Kann mir jemand helfen und meinen Tag retten. Ich muss alle Ereignisse im FullCalendar anzeigen. Vielen Dank im Voraus

+0

Was ist der Fehler Sie erhalten? –

+0

@Eyal Abir, Uncaught ReferenceError: doc ist nicht definiert – Keynes

+0

Ich habe meine Warnung aktualisiert (dynamic_events); Ich erhalte die Antwort, aber ich weiß nicht, wie man Ereignisse im Vollkalender machen kann – Keynes

Antwort

-1

Ihren Ajax-Code ändern zu diesen

$.ajax({ 
    url: "calendar/show_events", 
    type: 'POST', // Send post data 
    data: 'type=fetch_events', 
    async: true, 

    success: function(s){ 

      var dynamic_events = []; 
      $(s).find('event').each(function() { 
       dynamic_events.push({ 
        title: $(this).attr('title'), 
        start: $(this).attr('start') // will be parsed 
       }); 
      }); 
      callback(dynamic_events); 

      } 
});  
+0

Aber ich habe den Fehler so, wenn ich das mag .. Uncaught Error: Syntaxfehler, unerkannter Ausdruck: [{"title": "hi", "id": 1 , "start": "2016-05-30 00: 00: 00.000", "rendering": "Hintergrund", "backgroundColor": "# ff9999", "className": "event-full", "textColor": " weiß "}, {" title ":" vibrator "," id ": 3," start ":" 2016-05-26 00: 00: 00.000 "," rendering ":" hintergrund "," backgroundColor ":" # ff9999 "," className ":" event-full "," textColor ":" weiß "}, {" title ":" vibrator "," id ": 8," start ":" 2016-05-26 00:00 : 00.000 "," rendering ":" background "," backgroundColor ":" # ff9999 "," className ":" event-full "," textColor ":" weiß "}}] – Keynes

+1

Wann passiert das? Dieser String hat 2 Probleme, es gibt ein extra '}' vor dem Ende und aus irgendeinem Grund gibt es ein spezielles Zeichen, das wahrscheinlich Probleme macht. Ich kopiere es in [fiddle] (https://jsfiddle.net/fdj1cysy/) rein –