0

I running the following code, that has within also some quoted attempts that lead to failures:

$.post('Controller.php',
    {
        action: 'get_events'    
    },
    function(data, textStatus) {
        //var eventsInline = JSON.stringify(data); //Fails but comes in good direction.
        console.log(JSON.stringify(data));

        //This works, it is default
        var eventsInline = [{
                    "date": "1394220775280", 
                    "type": "meeting", 
                    "title": "Project A meeting", 
                    "description": "Lorem Ipsum dolor set", 
                    "url": "http://www.event1.com/" }]
        /*
        //ofcourse this fails
        $.each( data, function( index, calendar){

                    "date": calendar.event_sdate, 
                    "type": calendar.event_type, 
                    "title": calendar.event_title, 
                    "description": calendar.event_description, 
                    "url": calendar.event_url 
        });
        */
    $("#eventCalendarInline").eventCalendar({
        jsonData: eventsInline,
        showDescription: true
    }); 

     $('#indicator').hide();

    }, 
    "json"      
);

As stated the default code works. The console.log output is as following:

"[{
"0":"1",
"1":"1394220775280",
"2":"1402891200000",
"3":"meeting",
"4":"Project A meeting",
"5":"Lorem Ipsum dolor set",
"6":"http://www.event1.com/",

"event_id":"1",
"event_sdate":"1394220775280",
"event_edate":"1402891200000",
"event_type":"meeting",
"event_title":"Project A meeting",
"event_description":"Lorem Ipsum dolor set",
"event_url":"http://www.event1.com/"
}]"

It seems harder as i thought.

1 Answer 1

2
    $.post('Controller.php', {
        action: 'get_events'
    }, function(data, textStatus) {
        //var eventsInline = JSON.stringify(data); //Fails but comes in good direction.
        console.log(JSON.stringify(data));

        // Define the data
        var the_data = [];
        $.each(data, function(index, calendar) {
            // Fill "the_data" with each entry
            the_data.push({
                date:           calendar.event_sdate, 
                type:           calendar.event_type, 
                title:          calendar.event_title, 
                description:    calendar.event_description, 
                url:            calendar.event_url 
            });
        });

        $("#eventCalendarInline").eventCalendar({
            jsonData:           the_data,
            showDescription:    true
        }); 

        $('#indicator').hide();
    }, 'json');
Sign up to request clarification or add additional context in comments.

5 Comments

Yes sirrrrrrrrrrrrrrr!!! have to wait a few minute before can accept..But you are the winner.
show the comments to understand that. You must create an array. The you can filled it out with your data. After that you can use "the_data" on your Event Calendar
Strange to see where my first attempt "ofcourse this will fail" is closer to the answer as the one i thought would be haha.
Now i need to invent some genius plan to let it load only the content for the current selected month... but that is another story ;) answer is accepted..Thanks again!!
That u can realize on your PHP ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.