【发布时间】:2011-10-20 14:07:45
【问题描述】:
我已经尝试了一天多的时间来解决这个问题。我安装了 FullCalendar (v1.5.1),我正在使用 AgendaWeek。我安装了 asp.net v.3.5,我正在尝试使用 Json 提要中的事件填充日历,但它不起作用。这是我的代码和错误。如果有人可以提供帮助,那就太好了。
<script type="text/javascript">
$(document).ready(function() {
//$(".myClass").css("border", "3px solid red");
/* initialize the Web Service
-----------------------------------------------------------------*/
$(".external-events").empty();
$.ajax({
type: "POST",
async: false,
contentType: "application/json; charset=utf-8",
url: "StudiesWebService.asmx/Return_Available_Codes",
data: "{}",
dataType: "json",
success: function(data) {
var c = eval(data.d);
for (var i in c) {
$(".external-events").append(c[i]);
};
},
error: function(e) { $(".external-events").html("An Error Occured" + e); }
});
/* end of web service call
-----------------------------------------------------------------*/
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events div.external-event').each(function() {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim($(this).text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$(this).data('eventObject', eventObject);
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* end of initialize the external events
-----------------------------------------------------------------*/
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
header: {
left: '',
center: '',
right: ''
},
eventSources: [
// your event source
{
url: 'StudiesWebService.asmx/EventList',
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
// any other sources...
],
date: 17, //starting date.
contentHeight: 780, //height of the calendar
defaultEventMinutes: 60, //each droppable event is set to 60 min.
slotMinutes: 15, //slot time interval
defaultView: 'agendaWeek', //view to agenda week
minTime: 6, //start time
maxTime: 21, //end time
allDaySlot: true,
editable: true,
droppable: true, // this allows things to be dropped onto the calendar !!!
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
}
});
//End of Calendar
});
</script>
网络服务:
[WebMethod]
[ScriptMethod]
public string EventList(double start, double end)
{
var list = new List<string>();
list.Add("[{\"id\":\"36\"title\":\"Birthday party\",\"start\":\"2011-10-18 07:30\",\"end\":\"2011-10-18 10:30\",\"allDay\":false}]");
JavaScriptSerializer jss = new JavaScriptSerializer();
string strJSON = jss.Serialize(list.ToArray());
return strJSON;
}
Firebug 数据和错误
标题:
响应标头view source 日期 2011 年 10 月 20 日星期四 13:56:52 GMT 服务器 Microsoft-IIS/6.0 MicrosoftOfficeWebServer 5.0_Pub X-Powered-由 ASP.NET X-AspNet-版本 2.0.50727 json错误为真 缓存控制私有 内容类型应用程序/json;字符集=utf-8 内容长度 1063 请求标头view source 主机连接 用户代理 Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 接受 application/json, text/javascript, /; q=0.01 Accept-Language en-us,en;q=0.5 接受编码 gzip,放气 接受字符集 ISO-8859-1,utf-8;q=0.7,*;q=0.7 连接保持活动 内容类型应用程序/json;字符集=utf-8 X-Requested-With XMLHttpRequest 推荐人http://anessrv/fullcalendar/default6.aspx 内容长度 31 杂注无缓存 Cache-Control no-cache
帖子:
来源 开始=1318737600&结束=1319342400
回复:
{"Message":"Invalid JSON primitive: start.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer .DeserializeInternal(Int32 深度)\r\n 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串输入,Int32 depthLimit,JavaScriptSerializer 序列化程序)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer序列化程序、字符串输入、类型类型、Int32 depthLimit)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](字符串输入)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest (HttpContext 上下文,JavaScriptSerializer 序列化程序)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData 方法数据,HttpContext 上下文)\r\n 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext 上下文, WebServiceM ethodData methodData)","ExceptionType":"System.ArgumentException"}
【问题讨论】:
标签: json asmx fullcalendar