2010-04-19 59 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不喜歡。