2010-04-19 58 views
1

这是我的代码。它可以很好地获取数据和解析,但我无法显示事件。请让我知道可能的原因。在Asp.Net中使用webservices的JQUERY中的完整日历

我觉得回调(事件)在这里不起作用。

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 
        }); 
       } 

回答

0

我有这个问题,不管我怎么装饰类或.asmx文件的方法,我一直得到XML作为结果。我终于找到了一个链接,帮助我创建了一个标准的.aspx页面。 .aspx文件看起来是这样的:

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

而且我.aspx.cs文件是这样的:

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())); 
} 
} 

你可以猜到事件类的化妆,但它看起来是这样的:

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; 
} 

完整日历自1970年1月1日起使用秒数,因此使用“rootTime”。另外,startDate & endDate作为int来转换以修整小数位,而Full Calendar不喜欢。