Here is my jQuery code. It should parse the json returned by this php script. The php is known to work. It should also convert the date literals to a javascript date object. However, an error occurs at dates.length
. Can anyone see what is wrong with the code?
if($("#calendar").length)
{
var dates;
$.post("/dates/jsondates.php",function(data)
{
for(var i=0; i<data.length; i++)
{
data[i].start = new Date(data[i].start);
data[i].end = new Date(data[i].end);
}
dates = data;
}, "json");
$("#calendar").datepicker(
{
beforeShowDay: function(date)
{
for(var i=0; i<dates.length; i++)
{
if(dates[i].start<date<dates[i].end)
{
return new Array(0, "booked", dates[i].comment);
}
}
return new Array(1);
}
});
}