jQuery FullCalendar 事件函数回调未呈现我的事件
我正在为我正在处理的项目使用 jQuery FullCalendar 插件,并且尝试在日历中呈现从对 Java servlet 的请求返回的事件。 Servlet 将返回一个 XML 文档,然后我将解析该文档以构建一个事件,然后将其推入必要的数组,然后将其传递给回调函数。
代码
<html>
<head>
<link rel="stylesheet" type="text/css" href="fullcalendar.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="fullcalendar.min.js"></script>
<script type="text/javascript">
$(document.ready(function() {
$("#calendar").fullCalendar({
events: function(start, end, callback) {
$.get("servlet?command=getEvents", function(data) {
var events = [];
$(data).find("event").each(function() {
events.push({
id: $(this).find("id").text(),
title: $(this).find("title").text(),
start: $(this).find("start").text(),
end: $(this).find("end").text(),
url: $(this).find("url").text()
});
}
callback(events);
}, "xml");
}
});
});
</script>
</head>
<body>
<div id="calendar"></div>
</body>
</html>
从 Servlet 返回的
<xml>
<event>
<id>Event1</id>
<title>Title1</title>
<start>2011-10-18</start>
<end>2011-10-19</end>
<url>http://www.google.com</url>
</event>
// More Events...
</xml>
XML现在,似乎 XML 已从 Servlet 返回,而且数据的解析也正常工作。但是,事件本身并未呈现在日历中。我不完全确定 events
和 eventSources
之间有什么区别,但我已经尝试过这两种方法,但都无法正常工作。知道为什么(出于所有意图和目的)插件没有渲染文档中规定的事件数组中的事件吗?如果您需要更多详细信息或代码,请告诉我;我生成了上述必需品的模拟,所以这不是我的全部代码。
I'm using the jQuery FullCalendar plug-in for a project I'm working on, and I'm attempting to render events within the calendar that are returned from a request to a Java servlet. The servlet is to return an XML document which I then parse to build an event before pushing it into the necessary array that I then pass to the callback function.
Code
<html>
<head>
<link rel="stylesheet" type="text/css" href="fullcalendar.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="fullcalendar.min.js"></script>
<script type="text/javascript">
$(document.ready(function() {
$("#calendar").fullCalendar({
events: function(start, end, callback) {
$.get("servlet?command=getEvents", function(data) {
var events = [];
$(data).find("event").each(function() {
events.push({
id: $(this).find("id").text(),
title: $(this).find("title").text(),
start: $(this).find("start").text(),
end: $(this).find("end").text(),
url: $(this).find("url").text()
});
}
callback(events);
}, "xml");
}
});
});
</script>
</head>
<body>
<div id="calendar"></div>
</body>
</html>
XML Returned From Servlet
<xml>
<event>
<id>Event1</id>
<title>Title1</title>
<start>2011-10-18</start>
<end>2011-10-19</end>
<url>http://www.google.com</url>
</event>
// More Events...
</xml>
Now, it seems as though the XML is returned from the servlet as it should be, and the parsing of the data is working properly, too. However, the events themselves are not being rendered into the calendar. I'm not entirely sure what the difference is between events
and eventSources
, but I've tried both and had neither work properly. Any idea why -- for all intents and purposes -- the plug-in isn't rendering the events that seem to be within the events array as dictated by the documentation? Let me know if you need more details or code; I generated a mock of the necessities above, so it's not my whole code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道我还没有收到这个问题的任何答案,但我想我已经找到了我的问题。我的 servlet 返回的 XML 文件的</code> 标记有时无效;一些标题包含无效的 XML 字符,我需要在将文件发送回 AJAX 调用之前替换这些字符。使用下面提到的以下函数完成此操作后,我的所有事件都开始正确渲染。是的,我确实意识到可能有一种更有效的方法可以使用正则表达式或其他方式删除无效字符,但我尝试的所有方法都不起作用。这个功能虽然效率低下,但很有效......
I know that I haven't received any answers yet for this question, but I think I managed to figure out my issue. The
<title>
tags of the XML file my servlet was returning was sometimes invalid; some of the titles contained invalid XML characters that I needed to replace before shipping the file back to the AJAX call. Once that was done with the following function noted below, all of my events began rendering properly. And yes, I do realize that there is probably a more efficient way to remove invalid characters using regex or something, but everything I tried wasn't working. This function, though inefficient, works...