Javascript 从json源提取时未显示FullCalendar事件和资源

Javascript 从json源提取时未显示FullCalendar事件和资源,javascript,json,ajax,asp-classic,fullcalendar,Javascript,Json,Ajax,Asp Classic,Fullcalendar,我已经成功地使用asp在运行时注入fullcalendar的事件和资源的静态数组(我知道,它很古老,但它是我现在唯一的工具) 我想提高技能,所以现在我尝试将事件和资源指向生成数组的asp页面。我无法让这一点发挥作用-没有显示任何事件 在下面的代码中,我只需转到/resources.asp和/events.asp,精确复制输出,然后将其硬编码粘贴进去。日历工作完美,因此我可以合理地确定这两页产生了正确的输出。我看到的其他解决方案最终指出JSON或日期或其他格式不正确,但我确实将两个页面的输出粘贴进

我已经成功地使用asp在运行时注入fullcalendar的事件和资源的静态数组(我知道,它很古老,但它是我现在唯一的工具)

我想提高技能,所以现在我尝试将事件和资源指向生成数组的asp页面。我无法让这一点发挥作用-没有显示任何事件

在下面的代码中,我只需转到/resources.asp和/events.asp,精确复制输出,然后将其硬编码粘贴进去。日历工作完美,因此我可以合理地确定这两页产生了正确的输出。我看到的其他解决方案最终指出JSON或日期或其他格式不正确,但我确实将两个页面的输出粘贴进去,它们就工作了

相反,当我删除硬编码行并取消底部两行的注释以将日历指向两个asp页面时,日历不会显示任何内容。控制台告诉我这两个资源都已成功加载,我可以看到我希望看到的内容。控制台中看不到其他错误消息

我错过了什么

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');

  var calendar = new FullCalendar.Calendar(calendarEl, {
    schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
    displayEventTime : false,
    firstDay: 6,
   // plugins: [ 'resourceTimelinePlugin'],
   slotLabelInterval: {days:1},
   eventTimeFormat: { // will produce something like "Tuesday, September 18, 2018"
    hour: '2-digit',
    minute: '2-digit',
         hour12: false,
  },
    height: "auto",
    timeZone: 'UTC',
    initialView: 'resourceTimelineMonth',
    aspectRatio: 1.5,
    headerToolbar: {
      left: 'prev,next',
      center: 'title',
      right: 'resourceTimelineDay,resourceTimelineWeek,resourceTimelineMonth'
    },
    editable: true,
    resourceAreaHeaderContent: 'Work Orders',
    resources: [{id:'wo_3', title:'Work Order 57820'},{id:'comp_19', title:'Person in charge of possession (PICOP)', parentId: 'wo_3'},{id:'comp_20', title:'Track Safety Coordinator (TSC)', parentId: 'wo_3'},],
    events: [{title:'Unassigned',start:'2020-10-01 08:21',end:'2020-10-01 17:21', resourceId: 'comp_11', color: 'orange'},{title:'Unassigned',start:'2020-10-02 08:21',end:'2020-10-02 17:21', resourceId: 'comp_11', color: 'orange'},{title:'Unassigned',start:'2020-10-03 08:21',end:'2020-10-03 17:21', resourceId: 'comp_11', color: 'orange'},{title:'Unassigned',start:'2020-10-05 08:56',end:'2020-10-05 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-05 08:56',end:'2020-10-05 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-05 08:56',end:'2020-10-05 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-05 08:56',end:'2020-10-05 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-06 08:56',end:'2020-10-06 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-06 08:56',end:'2020-10-06 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-06 08:56',end:'2020-10-06 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-06 08:56',end:'2020-10-06 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-07 08:56',end:'2020-10-07 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-07 08:56',end:'2020-10-07 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-07 08:56',end:'2020-10-07 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-07 08:56',end:'2020-10-07 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-08 08:56',end:'2020-10-08 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-08 08:56',end:'2020-10-08 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-08 08:56',end:'2020-10-08 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-08 08:56',end:'2020-10-08 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-09 08:56',end:'2020-10-09 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-09 08:56',end:'2020-10-09 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-09 08:56',end:'2020-10-09 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-09 08:56',end:'2020-10-09 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-10 08:56',end:'2020-10-10 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-10 08:56',end:'2020-10-10 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-10 08:56',end:'2020-10-10 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-10 08:56',end:'2020-10-10 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-11 08:56',end:'2020-10-11 15:56', resourceId: 'comp_12', color: 'orange'},{title:'Unassigned',start:'2020-10-11 08:56',end:'2020-10-11 15:56', resourceId: 'comp_13', color: 'orange'},{title:'Unassigned',start:'2020-10-11 08:56',end:'2020-10-11 15:56', resourceId: 'comp_14', color: 'orange'},{title:'Unassigned',start:'2020-10-11 08:56',end:'2020-10-11 15:56', resourceId: 'comp_15', color: 'orange'},{title:'Unassigned',start:'2020-10-12 09:14',end:'2020-10-13 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-12 22:14',end:'2020-10-13 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-13 09:14',end:'2020-10-13 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-13 22:14',end:'2020-10-14 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-14 09:14',end:'2020-10-14 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-14 22:14',end:'2020-10-15 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-15 09:14',end:'2020-10-15 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-15 22:14',end:'2020-10-16 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-16 09:14',end:'2020-10-16 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-16 22:14',end:'2020-10-17 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-17 09:14',end:'2020-10-17 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-17 22:14',end:'2020-10-18 07:14', resourceId: 'comp_20', color: 'orange'},{title:'Unassigned',start:'2020-10-18 09:14',end:'2020-10-18 20:14', resourceId: 'comp_19', color: 'orange'},{title:'Unassigned',start:'2020-10-26 10:31',end:'2020-10-26 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-26 10:31',end:'2020-10-26 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-26 10:31',end:'2020-10-26 18:31', resourceId: 'comp_18', color: 'orange'},{title:'Unassigned',start:'2020-10-27 10:31',end:'2020-10-27 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-27 10:31',end:'2020-10-27 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-27 10:31',end:'2020-10-27 18:31', resourceId: 'comp_18', color: 'orange'},{title:'Unassigned',start:'2020-10-28 10:31',end:'2020-10-28 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-28 10:31',end:'2020-10-28 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-28 10:31',end:'2020-10-28 18:31', resourceId: 'comp_18', color: 'orange'},{title:'Unassigned',start:'2020-10-29 10:31',end:'2020-10-29 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-29 10:31',end:'2020-10-29 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-29 10:31',end:'2020-10-29 18:31', resourceId: 'comp_18', color: 'orange'},{title:'Unassigned',start:'2020-10-30 10:31',end:'2020-10-30 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-30 10:31',end:'2020-10-30 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-30 10:31',end:'2020-10-30 18:31', resourceId: 'comp_18', color: 'orange'},{title:'Unassigned',start:'2020-10-31 10:31',end:'2020-10-31 18:31', resourceId: 'comp_16', color: 'orange'},{title:'Unassigned',start:'2020-10-31 10:31',end:'2020-10-31 18:31', resourceId: 'comp_17', color: 'orange'},{title:'Unassigned',start:'2020-10-31 10:31',end:'2020-10-31 18:31', resourceId: 'comp_18', color: 'orange'},]
    //resources: '/resources.asp',
    //events: '/events.asp',
  });

  calendar.render();

});

好的,谢谢这里的输入,当然(畏缩)我的页面的响应中有一些HTML,但主要问题是:字段和数据似乎必须用“而不是撇号”来包装,以及最后的逗号(由于没有在代码中删除它的惰性)我们导致每个JSONLINT的JSON无效-但让我感到困扰的是,我的硬编码数据存在所有这些问题,而且FullCalendar无论如何都可以使用它们,没有问题。我想我认为这是可以原谅的,可以以同样的方式处理JSON输出页面

我只想说,在做了这些改变之后,现在一切都正常了


吸吮鸡蛋没有问题,我仍在学习这些东西,所以所有的指针都被感激地接受。

这似乎很奇怪。如果您的ASP脚本返回的是您在上面“事件:”和“资源”旁边粘贴的内容,那么“:那么它应该会起作用。因此,我唯一的假设是,当调用时,它们实际上可能不会准确地返回内容。您说您已经检查了输出(“我可以看到内容”),但不清楚您是如何做到这一点的。如果我在这里教你祖母吃蛋,我深表歉意,但最好是准确一点:打开浏览器的开发工具,转到网络工具,然后加载日历页。您应该会看到出现对events.asp和resources.asp的两个调用。依次单击每一个并检查以下内容:1)响应代码为200 OK。2) 内容类型响应头类似于application/json(不是HTML或其他任何内容)…3)响应选项卡中的原始数据完全是且仅是包含事件/资源数据的json数组,从
[
开始,以
]
结束。没有空白,没有HTML,没有奇怪的半隐藏UTF8字符,没有其他JSON对象-没有其他任何东西,只有数据。你确信
资源
事件
的ASP页面URL是正确的吗?正如@ADyson所说,你需要确保ASP页面响应没有其他内容(如果使用
Response.Buffer
是调用
Response.Clear
在使用
Response.Write
输出JSON字符串之前清除缓冲区,这是很好的经验法则),您甚至可能需要设置内容类型头
Response.ContentType=“application/JSON”
。通过在XHR上进行过滤来查看日历何时使用AJAX向ASP页面请求如何返回响应,应该很容易在浏览器开发工具中看到返回的内容。JSON!=Javascript文本,这可能就是原因。语法中显然有很多重叠,但实际上JSON格式在m中更为严格不管怎样,很高兴你把它修好了。