Help with displaying events from database

124 views
Skip to first unread message

Sheepish

unread,
Nov 5, 2009, 6:53:12 AM11/5/09
to jquery week calendar
Hi, I have been playing with this fantastic calendar over the last day
and I am struggling with getting events back out of the database.

I have tried various code from examples here and there and I think I
am closest with what I have now but it still doesnt work.

So, in the week calendar setup I have :
data: "sections/calendar/get_events.ajax.php"

according to firebug it returns :
events:[{"id":1,"start":
"2009-11-5T10:00:00-00:00","end":"2009-11-5T14:00:00-00:00","title":"Lunch
with Mike"}]

which i am sure is in the correct format and timestamp.

Could anyone point out where I am going wrong or what to try next?

Alexandre APPERCE

unread,
Nov 5, 2009, 3:16:50 PM11/5/09
to jquery week calendar
the date is wrong !

it must be

2009-11-05 not 2009-11-5

so :

events:[{"id":1,"start":
"2009-11-05T10:00:00-00:00","end":"2009-11-05T14:00:00-00:00","title":"Lunch
with Mike"}]

Sheepish

unread,
Nov 18, 2009, 6:24:27 AM11/18/09
to jquery week calendar
I have corrected the date and now firebug shows that this is being
returned from GET

events:[{"id":
1,"start":"2009-11-18T10:00:00-00:00","end":"2009-11-18T14:00:00-00:00","title":"Lunch
with Mike"}]

but still nothing shows on the calendar! No javascript or firebug
errors.

If i create the exact same events object in just the javascript :

~
data : function(start, end, callback) {
callback(getEventData());
}
~
function getEventData() {
return {
events : [
{"id":
1,"start":"2009-11-18T10:00:00-00:00","end":"2009-11-18T14:00:00-00:00","title":"Lunch
with Mike"}
]
};
}

It works fine! This is driving me nuts, i have tried a dozen
different things to try narrow down whats going on but I am getting
nowhere. Please help?

Rob Monie

unread,
Nov 18, 2009, 5:24:51 PM11/18/09
to jquery-wee...@googlegroups.com
Just quickly looking at your date format there it's not one I recognise and i'm a bit surprised it works when defined in javascript.  I can't remember the details of the parsing off hand biut if you return a format like the examples you'll. One thing to not in the examples is that the milliseconds are 000 not 00 which catches some people.

From the example:

events:[{"id":10182,
      "start":"2009-05-03T12:15:00.000+10:00",
      "end":"2009-05-03T13:15:00.000+10:00",
      "title":"Lunch with Mike"
    }, {
      "id":10182,
      "start":"2009-05-03T14:00:00.000+10:00",
      "end":"2009-05-03T15:00:00.000+10:00",
      "title":"Dev Meeting"
    }]

Sheepish

unread,
Nov 19, 2009, 5:36:09 AM11/19/09
to jquery week calendar
I am using the date format as used in the events.json example file in
the weekcalendar download and like I say it works fine when put
straight into the javascript, just not when passed through GET. Does
anyone have any example code of how they pass an events object from a
php script to weekcalendar? Im thinking I might just code this
akwardly and have php echo the javascript to create the events object.

Rob Monie

unread,
Nov 19, 2009, 5:14:14 PM11/19/09
to jquery-wee...@googlegroups.com
Could you confirm your date format because looking at your example you have

2009-11-18T10:00:00-00:00

whereas a date in the events.json file looks like this:

2009-05-03T12:15:00.000+10:00

Sheepish

unread,
Nov 24, 2009, 9:18:38 AM11/24/09
to jquery week calendar
The date I was using was valid but altered so it would appear on the
day I was testing.

I found what the problem was. When using

data: "sections/calendar/get_events.ajax.php"

the return must be
[{"id":
1,"start":"2009-11-24T10:00:00-00:00","end":"2009-11-24T14:00:00-00:00","title":"Lunch
with Mike"}]
not
events:[...]

Thats great, its working now but I can see this slowing down when the
calendar fills up since its loading the entire json in at once.
So now I want to load them in as the week is changed. Adapting the
weekcalendar example I now have

data: function(start, end, callback) {
var s = start.getTime();
var e = end.getTime();

$.post("sections/calendar/get_events.ajax.php", { start: s, end:
e },
function(result) {
alert(result);
if(result!="") {
callback(result);
} else {
callback([]);
}
});
}

This works exactly the same, the php returns the relevant json for the
week (the alert works fine) but it is the callback that is causing the
problem. Firebug reports :
G is undefined
[Break on this error] (function(){var l=this,g,y=l.jQuery,p=l....each
(function(){o.dequeue(this,E)})}});\n

and now I am completely stuck again.

Thanks in advance for any help.

On Nov 19, 10:14 pm, Rob Monie <robmo...@gmail.com> wrote:
> Could you confirm your date format because looking at your example you have
>
> 2009-11-18T10:00:00-00:00
>
> whereas a date in the events.json file looks like this:
>
> 2009-05-03T12:15:00.000+10:00
>

Rob Monie

unread,
Nov 24, 2009, 9:57:08 PM11/24/09
to jquery-wee...@googlegroups.com
That looks like a jquery issue so i'm not sure what's causing it. I would recommend using a get instead of a post for retrieving your data. This is a better use of the http methods as you're not posting form data, rather you're retrieving resources.

I don't think this has anything to do with your problem though. Can you debug it more and figure out the exact line that's causing this ? I think it's just a processing off elimination that's needed to isolate the problematic code. There's nothing that you're trying to do that should be a problem so it'll be something basic I think.

Sheepish

unread,
Nov 27, 2009, 7:31:00 AM11/27/09
to jquery week calendar
Thanks for the continued help Rob, I am getting there slowly and I
hope I wont be pestering you for too much longer :)

Ok, so using

data: function(start, end, callback) {
var s = start.getTime();
var e = end.getTime();

$.get("sections/calendar/get_events.ajax.php", { start: s, end:
e },
function(result) {
if(result!="") {
callback(result);
} else {
callback([]);
}
});
}
and having the php return
[{"id":1, "start":"2009-11-27T13:15:00.000+00:00",
"end":"2009-11-27T14:15:00.000+00:00", "title":"Lunch with Mike"}]
exactly the same return as
data: "sections/calendar/get_events.ajax.php" (which recieves and
displays the events perfectly)
results in
G is undefined
[Break on this error] (function(){var
l=this,g,y=l.jQuery,p=l....each(function(){o.dequeue(this,E)})}});\n
which you are right is a jquery error on line 12, the very start of
jquery.

So... rearranging things a little...
data: function(start, end, callback) {
var s = start.getTime();
var e = end.getTime();

$.get("sections/calendar/get_events.ajax.php", { start: s, end:
e },
function(result) {
if(result!="") {
var r = {events:[{"id":1,
"start":"2009-11-27T13:15:00.000+00:00",
"end":"2009-11-27T14:15:00.000+00:00", "title":"Lunch with Mike"}]};
callback(r);
} else {
callback([]);
}
});
}
Works perfectly, which leads me to believe that whatever im passing
back in the callback isnt a proper js object, somehow. So...

data: function(start, end, callback) {
var s = start.getTime();
var e = end.getTime();

$.get("sections/calendar/get_events.ajax.php", { start: s, end:
e },
function(result) {
alert(result);
if(result!="") {
var r = {events:[result]};
callback(r);
} else {
callback([]);
}
});
}
and no matter what the php returns, whether its
[{"id":1, "start":"2009-11-27T13:15:00.000+00:00",
"end":"2009-11-27T14:15:00.000+00:00", "title":"Lunch with Mike"}]
or
{"id":1, "start":"2009-11-27T13:15:00.000+00:00",
"end":"2009-11-27T14:15:00.000+00:00", "title":"Lunch with Mike"}
or simply a string of
test
results in firebug complaining on line 1141
d is undefined
[Break on this error] return new Date(d.getTime());\r\n
so I still think the object isnt constructed properly.

To clarify the js is recieving the php GET string. But how do i turn
this into an object that the callback understands?


Thanks so much if you can help me get any nearer to solving this!


On Nov 25, 2:57 am, Rob Monie <robmo...@gmail.com> wrote:
> That looks like a jquery issue so i'm not sure what's causing it. I would
> recommend using a get instead of a post for retrieving your data. This is a
> better use of the http methods as you're not posting form data, rather
> you're retrieving resources.
>
> I don't think this has anything to do with your problem though. Can you
> debug it more and figure out the exact line that's causing this ? I think
> it's just a processing off elimination that's needed to isolate the
> problematic code. There's nothing that you're trying to do that should be a
> problem so it'll be something basic I think.
>

Rob Monie

unread,
Nov 29, 2009, 1:06:31 AM11/29/09
to jquery-wee...@googlegroups.com
Have you tried using $.getJSON(...) ?   $.get(...) will not parse into a json object.
Reply all
Reply to author
Forward
0 new messages