ИЗМЕНЕНО для отображения новой функциональности:
В настоящий момент у меня реальная проблема с моим fullCalendar, и я никак не могу понять, что происходит?
Я использую общий обработчик ASP.NET для обработки запроса AJAX.
Мой fullCalendar инициализируется так:
$(document).ready(function() {
var now = new Date();
$("#CalendarControl").fullCalendar({
defaultView: 'agendaWeek',
allDaySlot: false,
minTime: 7,
maxTime: 20,
firstDay: now.getDay(),
events: "AjaxCalendarHandler.ashx?assessorIds=2"
//events: [{id:1,title:"FLEPI01 Agent Office 1\\n17-21 London Street SP10 2NU",start:Date(1300620600000),end:Date(1300624200000),className:"2",allDay:false}]
});
})
И мой файл Ashx:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AjaxCalendarHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write(Instruction.GetCalendarData(context.Request.QueryString["assessorIds"], context.Request.QueryString["start"], context.Request.QueryString["end"]));
}
public bool IsReusable
{
get
{
return false;
}
}
}
Здесь можно найти отредактированное содержимое И этот метод не делает ничего, кроме этого:
public static string GetCalendarData(string assessorIds, string startString, string endString)
{
StringBuilder json = new StringBuilder();
json.Append("[");
DateTime startDate, endDate;
Double startDouble, endDouble;
if (Double.TryParse(startString, out startDouble))
startDate = ConvertFromUnixTimestamp(startDouble);
else if (!DateTime.TryParse(startString, out startDate))
throw new ArgumentException("Start date must be specified");
if (Double.TryParse(endString, out endDouble))
endDate = ConvertFromUnixTimestamp(endDouble);
else if (!DateTime.TryParse(endString, out endDate))
throw new ArgumentException("End date must be specified");
DataAccess m_daccess = new DataAccess();
DataSet ds = new DataSet();
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@AssessorIds", assessorIds);
param[1] = new SqlParameter("@StartDate", startDate);
param[2] = new SqlParameter("@EndDate", endDate);
m_daccess.Fetch("up_Instruction_GetCalendarData", out ds, param);
if (ds.Tables.Count > 0)
{
string jsonDelim = string.Empty;
foreach (DataRow dr in ds.Tables[0].Rows)
{
fullCalendarDiaryEvent Event = new fullCalendarDiaryEvent(dr);
json.Append(jsonDelim + Event.ToJSON());
jsonDelim = ",";
}
}
json.Append("]");
return json.ToString();
}
private class fullCalendarDiaryEvent
{
public int id { get; set; }
public string title { get; set; }
public double start { get; set; } // **Treat these as doubles, rather than dates, as the ToJSON() method deals with dates in a different manner to that required by fullCalendar!!! **
public double end { get; set; }
public string className { get; set; }
public bool allDay { get { return false; } }
public fullCalendarDiaryEvent() {
this.id = -1;
this.title = string.Empty;
this.start = 0;
this.end = 0;
this.className = string.Empty;
}
public fullCalendarDiaryEvent(int _id, string _title, DateTime _start, DateTime _end, string _className)
: this()
{
this.id = _id;
this.title = _title;
this.start = ConvertToUnixTimestamp(_start);
this.end = ConvertToUnixTimestamp(_end);
this.className = _className;
}
public fullCalendarDiaryEvent(DataRow data)
: this()
{
if (data["Id"] != null) this.id = Convert.ToInt32(data["Id"]);
if (data["title"] != null) this.title = Convert.ToString(data["title"]);
if (data["start"] != null) this.start = ConvertToUnixTimestamp(Convert.ToDateTime(data["start"]));
if (data["end"] != null) this.end = ConvertToUnixTimestamp(Convert.ToDateTime(data["end"]));
if (data["className"] != null) this.className = Convert.ToString(data["className"]);
}
}
Итак, как вы можете видеть, веб-служба возвращает строку, это точно то же самое, что и закомментированная строка в сценарии установки fullCalendar.
Моя проблема заключается в том, что когда эта строка возвращается через веб-сервис, в календаре ничего не отображается, но если я передамСобытие в виде массива, оно работает нормально (например, раскомментируйте строку событий).
Я не знаю, почему это так, и на самом деле нет никаких полезных примеров для того, что такое JSON.содержимое должно выглядеть так, как будто оно возвращено из другогоее страница.
Мой уровень разочарования в настоящий момент настолько высок, мне действительно нужна помощь ....
Большое спасибо.
PS Это мое первое сообщение, так чтопожалуйста, будь милым.