Fullcalendar未顯示ajax獲取的事件。事件成功通過,因爲我可以通過彈出來顯示它,但它不會顯示在日曆中。 fullcalendar將顯示事件,如果我手動設置事件,但一旦我使用它無法呈現的.cs文件的數據傳遞。fullcalendar無法顯示事件
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web.Services;
using System.Linq;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Collections;
using System.Data;
namespace TravelPlannerO
{
public partial class Schedule : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class Event
{
public string id { get; set; }
public string title { get; set; }
public string start { get; set; }
public string end { get; set; }
public string desc { get; set; }
public string status { get; set; }
public Event(string id, string title, string start, string end,string desc,string status)
{
this.id = id;
this.title = title;
this.start = start;
this.end = end;
this.desc = desc;
this.status = status;
}
};
[WebMethod]
public static string GetEvent()
{
string strSelect;
SqlCommand cmdSelect;
SqlDataReader dtr;
SqlConnection conn;
string connStr = ConfigurationManager.ConnectionStrings["plannerdb"].ConnectionString;
conn = new SqlConnection(connStr);
strSelect = "Select * from [Source.SavedPlan]";
cmdSelect = new SqlCommand(strSelect, conn);
conn.Open();
dtr = cmdSelect.ExecuteReader();
<script src="Scripts/moment.min.js"></script>
<script src="Scripts/jquery-ui.custom.min.js"></script>
<script src="Scripts/fullcalendar.min.js"></script>
<script type="text/javascript">
var listofevent;
\t $(document).ready(function() {
\t $('#calendar').fullCalendar({
\t \t header: {
\t \t \t left: 'prev,next today',
\t \t \t center: 'title',
\t \t \t right: 'month,agendaWeek,agendaDay'
\t \t \t },
events:function (id,title,start, end, callback) {
\t \t \t $.ajax({
\t \t \t type: "POST ",
\t \t \t url: '<%=Microsoft.AspNet.FriendlyUrls.FriendlyUrl.Resolve(" /Schedule.aspx/GetEvent ")%>',
\t \t \t data: {},
\t \t \t contentType: "application/json;charset = utf - 8 ",
\t \t \t dataType: "json ",
\t \t \t success: function (list) {
\t \t \t \t listofevent = list.d;
\t \t \t \t alert(listofevent);
\t \t \t \t var events = [];
\t \t \t \t alert(list.d);
\t \t \t \t var obj = $.parseJSON(list.d);
\t \t \t \t console.log(obj);
\t \t \t \t \t \t \t
\t \t $(list).find('event').each(function() { \t \t \t
\t \t \t events.push({
\t \t \t title: $(this).attr('title'),
\t \t \t start: $(this).attr('start'),
\t \t \t end: $(this).attr('end') \t
\t \t \t \t });
\t \t \t console.log(obj.calEvent);
\t \t \t \t \t });
\t \t \t //callback(events);
\t \t \t callback && callback(events);
\t \t \t \t },
\t \t \t error: function (xhr, status, error) {
\t \t \t \t alert(xhr.responseText);
\t \t \t \t \t }
\t \t \t \t \t }); \t
\t \t \t \t },
\t \t \t \t defaultDate: '2015-1-1',
\t \t \t \t selectable: true,
\t \t \t \t editable: true,
\t \t \t \t selectHelper: true,
\t \t \t \t eventLimit: true, // allow "
more " link when too many events
</script>
<link href="Content/fullcalendar.css" rel="stylesheet" /> <link href="Content/fullcalendar.print.css" rel="stylesheet" media="print" /> <link href="Content/jquery-ui.min.css" rel="stylesheet"/>
<div id='calendar'></div>
List<object> array = new List<object>();
if (dtr.HasRows)
{
var index_id = dtr.GetOrdinal("PlanId");
var index_title = dtr.GetOrdinal("Name");
var index_start = dtr.GetOrdinal("DateFrom");
var index_end = dtr.GetOrdinal("DateTo");
var index_desc = dtr.GetOrdinal("Description");
var index_status = dtr.GetOrdinal("Status");
while (dtr.Read())
{
var id = dtr.GetValue(index_id).ToString();
var title = dtr.GetValue(index_title).ToString();
var datestart = dtr.GetValue(index_start).ToString();
var dateend = dtr.GetValue(index_end).ToString();
var desc = dtr.GetValue(index_desc).ToString();
var status = dtr.GetValue(index_status).ToString();
DateTime RealStartDate = Convert.ToDateTime(datestart);
DateTime RealEndDate = Convert.ToDateTime(dateend);
string start = RealStartDate.ToString("s");
string end = RealEndDate.ToString("s");
Event eventrows = new Event(id, title, start, end,desc,status);
array.Add(eventrows);
}
}
string myJsonString = (new JavaScriptSerializer()).Serialize(array);
return myJsonString;
}
private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
}
}