获取事件时出现问题 完整日历 asp.net / c#



首先,我会说我在这里尝试了很多很多样本,而其他样本没有成功,所以在这里发布以提出建议。

我正在使用完整日历。

这是开始:

$('#calendar')
.fullCalendar({
allDaySlot: false,
customButtons: {
reload: {
text: '+1 Year',
click: function() {
$('#calendar').fullCalendar('gotoDate', new Date(new Date().setFullYear(new Date().getFullYear() + 1)));
}
}                           
},     
themeSystem: 'bootstrap4',
defaultView: 'agendaWeek',
eventClick: updateEvent,
selectable: true,
selectHelper: true,
events: "JsonResponse.ashx", 
and other attributes.....

问题是日历没有显示事件。

JsonResonse.ashx返回一个字符串,如下所示:

[{id: '1029',title: 'mr 1',clientphone: '1234556654',clientemail: 'mr1@gmail.com',start:  '2018-05-21 10:00',end: '2018-05-21 11:45',allDay:false,description: 'New test on a new calender'},{id: '1030',title: 'mr 2',clientphone: '123456',clientemail: 'mr2@gmail.com',start:  '2018-05-25 09:00',end: '2018-05-25 11:45',allDay:false,description: 'i like pringles'}]

但是在火狐上,我看到它不会使事件出现一些错误,说:

SyntaxError: JSON.parse: expected property name or '}' at line 1 column 3 of the JSON data

所以我采用和替换事件:"JsonResponse.ashx",返回的字符串

[{id: '1029',title: 'mr 1',clientphone: '1234556654',clientemail: 'mr1@gmail.com',start:  '2018-05-21 10:00',end: '2018-05-21 11:45',allDay:false,description: 'New test on a new calender'},{id: '1030',title: 'mr 2',clientphone: '123456',clientemail: 'mr2@gmail.com',start:  '2018-05-25 09:00',end: '2018-05-25 11:45',allDay:false,description: 'i like pringles'}]

使 JSON 返回的代码:

return "{" +
"id: '" + cevent.id + "'," +
"title: '" + HttpContext.Current.Server.HtmlEncode(cevent.title) + "'," +
"clientphone: '" + HttpContext.Current.Server.HtmlEncode(cevent.clientphone) + "'," +
"clientemail: '" + HttpContext.Current.Server.HtmlEncode(cevent.clientemail) + "'," +
"start:  '" + (cevent.start).ToString("yyyy-MM-dd HH:mm") + "'," +
"end: '" + (cevent.end).ToString("yyyy-MM-dd HH:mm") + "'," +
"allDay:" + allDay + "," +
"description: '" + HttpContext.Current.Server.HtmlEncode(cevent.description) + "'" +
"},";

基本上我合并所有事件,然后返回。

就像那样,它工作正常并将事件放在日历上。我在这里做错了什么?

谢谢

根据您更新的问题,您需要像这样更新 json 生成代码:

return "{" +
""id": "" + cevent.id + ""," +
""title": "" + HttpContext.Current.Server.HtmlEncode(cevent.title) + ""," +
""clientphone": "" + HttpContext.Current.Server.HtmlEncode(cevent.clientphone) + ""," +
""clientemail": "" + HttpContext.Current.Server.HtmlEncode(cevent.clientemail) + ""," +
""start":  "" + (cevent.start).ToString("yyyy-MM-dd HH:mm") + ""," +
""end": "" + (cevent.end).ToString("yyyy-MM-dd HH:mm") + ""," +
""allDay":" + allDay + "," +
""description": "" + HttpContext.Current.Server.HtmlEncode(cevent.description) + """ +
"},";

JsonResponse.ashx handler 返回的 json 无效。你如何生成 json?我建议使用 NewtonSoft 使用 JsonConvert.SerializeObject 方法将事件列表序列化为 json

下面是 ashx 处理程序应返回的有效 json。请注意属性名称和值两边的双引号。

[{
"id": "1029",
"title": "mr1",
"clientphone": "1234556654",
"clientemail": "mr1@gmail.com",
"start": "2018-05-2110: 00",
"end": "2018-05-2111: 45",
"allDay": false,
"description": "Newtestonanewcalender"
},
{
"id": "1030",
"title": "mr2",
"clientphone": "123456",
"clientemail": "mr2@gmail.com",
"start": "2018-05-2509: 00",
"end": "2018-05-2511: 45",
"allDay": false,
"description": "ilikepringles"
}]

相关内容

  • 没有找到相关文章

最新更新