views:

259

answers:

4

Hi, this is my code. It works fine for getting data and parsing, but I am unable to get events displayed. Please let me know the possible reason.

I feel that the callback(event) is not working here.

 events: function(callback)
                {
                    $.ajax({
                        type: "POST",
                        url: "WebService.asmx/hello",
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(data)
                        {
                            var evnt = [];
                            $(data.d).find('event').each(function()
                            {

                                evnt.push({
//                                    title: $(this).attr('title'),
//                                    start: $(this).attr('start'),
                                //                                    end: $(this).attr('end')
                                       title: 'Events1',
                                       start: '2010-04-01',
                                       end: '2010-04-10'
                                });

                            });
                              alert('called end');
                            callback(evnt);

                        },
                        error: OnError
                    });
                }
A: 

I believe start and end need to be Date objects

title: 'Events1',
start: new Date(2010, 4, 1),
end: new Date(2010, 4, 10)

See the documentation: http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

Joel Potter
A: 

hi,

i know that i can use xml data also to perform this.. but i require example of how xml looks..like.... for the events...

A: 

I wrote up an example of how to get FullCalendar working in ASP.NET using a webservice.

http://jake1164.blogspot.com/2010/06/jquery-fullcalendar-and-aspnet.html

Jake1164
A: 

I had this problem and no matter how I decorated the class or the method in the .asmx file, I kept getting XML as the result. I finally found a link that helped me create just a standard .aspx page. The .aspx file looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ScheduledEvents.aspx.cs" Inherits="ScheduledEvents" %>

And my .aspx.cs file is this:

public partial class ScheduledEvents : System.Web.UI.Page
{
 protected override void Render(HtmlTextWriter writer)  
 {
   List<Event> itemList = new List<Event>();
   for (int i = 0; i < 5; ++i)
   {
        Event newEvent = new Event();
        newEvent.id = i;
        newEvent.className = "";
        newEvent.title = "Test";
        newEvent.start = (((int)DateTime.Now.AddDays(i).ToUniversalTime().Subtract(Event.rootTime).TotalSeconds)).ToString();
        newEvent.end = (((int)DateTime.Now.AddDays(i).AddMinutes(60).ToUniversalTime().Subtract(Event.rootTime).TotalSeconds)).ToString();
        newEvent.url = "http://www.google.com";
        newEvent.allDay = false;
        itemList.Add(newEvent);
   }
   Response.Clear();
   Response.ContentType = "application/json";
   Response.Write(new JavaScriptSerializer().Serialize(itemList.ToArray()));  
 }
}

You can guess the makeup of the Event class, but it looks like this:

public class Event
{
  public static readonly DateTime rootTime = DateTime.Parse("1970-01-01 00:00:00");
  public int id = default(int);
  public string className = string.Empty;
  public string title = string.Empty;
  public string start = string.Empty;
  public string end = string.Empty;
  public string url = string.Empty;
  public bool allDay = false;
}

Full Calendar uses seconds since 1/1/1970, thus the use of "rootTime". Also, the startDate & endDate are casted as int to trim the decimal places, which Full Calendar does not like.

jm32