Jquery Fullcalendar未发布有效的JSON
我只是不知道这段代码有什么问题,我已经将所有依赖项加载到了jquery 1.9.1 jquery UI 1.10.2、fullcalendar.min.js中,并且按照示例所示进行操作 以下是我的ajax调用:Jquery Fullcalendar未发布有效的JSON,jquery,json,fullcalendar,Jquery,Json,Fullcalendar,我只是不知道这段代码有什么问题,我已经将所有依赖项加载到了jquery 1.9.1 jquery UI 1.10.2、fullcalendar.min.js中,并且按照示例所示进行操作 以下是我的ajax调用: $(document).ready(function() { $('#calendar').fullCalendar({ events: { type: 'POST', url: '
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
type: 'POST',
url: 'mypage.cfc',
data: JSON.stringify({ param_one: "test", param_two: "testing"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function() {
//alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
});
});
在coldfusion后端页面,也就是预期的JSON页面上,我不断收到JSON解析失败的消息,因此我检查了firebug,查看帖子中发送的内容,以及它没有发送有效的JSON数据。以下是firebug在帖子中展示的内容:
0=%7B&1=%22&2=p&3=a&4=r&5=a&6=m&7=_&8=o&9=n&10=e&11=%22&12=%3A&13=%22&14=t&15=e&16=s&17=t&18=%22&19=%2C&20=%22&21=p&22=a&23=r&24=a&25=m&26=_&27=t&28=w&29=o&30=%22&31=%3A&32=%22&33=t&34=e&35=s&36=t&37=i&38=n&39=g&40=%22&41=%7D&start=1361685600&end=1365310800
我还尝试过完全精简代码,看看是否可以缩小问题的范围,所以我很累:
$(document).ready(function() {
$('#calendar').fullCalendar({
events: 'mypage.cfc'
});
});
在这种情况下,根本没有发布任何get。我在“参数”选项卡中看到:
_ 1364228830548
end 1365310800
format json
start 1361685600
我错过了什么?有什么想法吗?解决方案: 好吧,我希望这能帮助其他人解决这个问题。感谢ganeshk为我指明了正确的方向。fullcalendar的文档很少,我以为jquery代码应该发送JSON数据,但事实并非如此。它只发送一个字符串 在coldfusion端,如果要捕获字符串,可以使用如下内容:
<!--- query string --->
<cfset URLstring = getHTTPRequestData().content >
<!--- local structure --->
<cfset cfData = StructNew()>
<!--- loop our query string values and set them in our structure --->
<cfloop list="#URLstring#" index="key" delimiters="&">
<cfset cfData["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))>
</cfloop>
然后在SQL语句的代码中,可以使用#cfData[“start”]#或传递的任何其他参数
查询完成后,您可以填充一个数组并将其发送回,它将填充日历。为什么要尝试字符串化?
数据:{param_one:“test”,param_two:“testing”}
不起作用吗?@ganeshk我先尝试了w/o stringify,它也没有发布有效的JSON。W/O stringify这个帖子看起来是这样的:param_one=test¶m_two=testing&start=1361685600&end=1365310800这是正确的,对吗?难道你的coldfusion后端不能处理这个问题吗?问题可能是FullCalendar从不以JSON格式发送任何内容,但它“期待”JSON格式的结果。@ganeshk谢谢你为我指明了正确的方向。