Error in Fullcalendar with json and web2py
Question: I´m calling:

    
    
    events: {
        url: '/CondominioVip/evento/evento_json.json',
        error: function() {
            alert('there was an error while fetching events!');
        }
    }
    

I've also tried to add `type: 'POST` but it didn't work either.

My controller:

    
    
    def evento_json():
        events= "[{'title':'event1','start':'2010-01-01'},{'title':'event3','start':'2010-01-09 12:30:00','allDay':False}]"
        return events
    

Test call from browser
(`http://localhost:8000/CondominioVip/evento/evento_json.json`):

>
> [{'title':'event1','start':'2010-01-01'},{'title':'event3','start':'2010-01-09
> 12:30:00','allDay':False}]

Request from web2py ajax function:

> Accept:application/json, text/javascript, _/_ ; q=0.01  
>  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3  
>  Accept-Encoding:gzip,deflate,sdch  
>  Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4  
>  Cache-Control:max-age=0  
>  Connection:keep-alive  
>  Content-Length:31  
>  Content-Type:application/x-www-form-urlencoded  
>  Cookie:session_id_admin=127.0.0.1-f9db7d99-4e7e-4bae-a229-d6614e9599f0;
> cvip_language=pt-BR;
> session_id_condominiovip=127.0.0.1-b820cbe3-9a55-40bb-8618-8d3f9a43f7c2  
>  Host:`localhost:8000`  
>  Origin:`http://localhost:8000`  
>  Referer:`http://localhost:8000/CondominioVip/evento/index/2`  
>  User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like
> Gecko) Chrome/19.0.1084.46 Safari/536.5  
>  X-Requested-With:XMLHttpRequest

Response headers:

> Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0  
>  Connection:keep-alive  
>  Content-Length:105  
>  Content-Type:application/json  
>  Date:Tue, 29 May 2012 02:54:04 GMT  
>  Expires:Tue, 29 May 2012 02:54:03 GMT  
>  Pragma:no-cache  
>  Server:Rocket 1.2.4 Python/2.7.3  
>  Set-Cookie:cvip_language=pt-BR; expires=Wed, 30-May-2012 02:54:04 GMT;
> Path=/,
> session_id_condominiovip=127.0.0.1-b820cbe3-9a55-40bb-8618-8d3f9a43f7c2;
> Path=/  
>  X-Powered-By:web2py

Response:

>
> [{'title':'event1','start':'2010-01-01'},{'title':'event3','start':'2010-01-09
> 12:30:00','allDay':False}]

I'm out of options. Any help would be apprecianted.

Update:

I've installed the JsonView extension on Chrome, so returning a string is not
considered a json response.

I made some changes:

    
    
    def evento_json():
        rows = db(evento.id>0).select(evento.id,evento.titulo,evento.data_hora_inicio,evento.data_hora_fim)
        events = []
        for row in rows:
            event = {'title': row['titulo'],
                     'start': row['data_hora_inicio'],
                     'end': row['data_hora_fim'],
                     'allDay': False,
                     'url': URL(c='evento', f='index', args=[row['id']], extension=False)}
            events.append(event)
        return events
    

But web2py throws an error. I´ve printed "events" and "json(events)" before
send it to generic.json, and the format is exactly what fullcalendar expects.

The way I found to stop the error is:

In controller:

    
    
    def evento_json():
        import datetime
        start = datetime.datetime.fromtimestamp(int(request.vars['start'])).strftime('%Y-%m-%d %H:%M:%S')
        end = datetime.datetime.fromtimestamp(int(request.vars['end'])).strftime('%Y-%m-%d %H:%M:%S')
        set = db((evento.id>0) &
                 (evento.data_hora_inicio >= start) &
                 (evento.data_hora_fim <= end))
    
        if (not auth.has_membership(auth.id_group(role='site_admin'), auth.user.id)) and \
           (not auth.has_membership(auth.id_group(role='cond_admin'), auth.user.id)):
            set = set(evento.flag_disp==True)
    
        rows = set.select(evento.id,
                          evento.titulo,
                          evento.data_hora_inicio,
                          evento.data_hora_fim,
                          evento.flag_disp)
    
        events = []
        for row in rows:
            event = {'title': row['titulo'],
                     'start': row['data_hora_inicio'],
                     'end': row['data_hora_fim'],
                     'allDay': False,
                     'url': URL(c='evento', f='index', args=[row['id']], extension=False),
                     'color': 'blue' if row['flag_disp'] is True else 'red'}
            events.append(event)
    
        if events:
            from gluon.serializers import json
            return XML(json(events))
        else:
            return '{}'
    

And create a view evento/evento_json.json with the following:

> {{=response._vars)}}

It works! But seems a bug to me. I'm not sure if I'm doing something wrong.


Answer: Maybe try:

    
    
    events= "[{'title':'event1','start':'2010-01-01'},{'title':'event3','start':'2010-01-09T12:30:00Z','allDay':false}]"
    

(Changed the event3 start date/time to ISO8601 format as per the
[API](http://arshaw.com/fullcalendar/docs/event_data/Event_Object/), and
changed "False" to "false".)

