我从服务器端页面(getEvents.cfm)返回以下字符串。我在ColdFusion中工作。
[
{
title: 'Event1',
start: '2012-02-02',
end: '2012-02-02',
allDay: 'no'
},
{
title: 'Event2',
start: '2012-02-03',
end: '2012-02-03',
allDay: 'no'
}
]
但我在页面加载时出错"获取事件时出错!"
以下是我用来获取事件的代码:
eventSources: [
// your event source
{
url: '../getevents.cfm',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
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...
]
首先,allDay
应该是true/false,而不是no/yes。第二,返回字符串应该是这样的:
[{
"title": 'Event2',
"start": '2012-02-03',
"end": '2012-02-03',
"allDay": 'false'
}]
$.getJSON('path_to_your_json_file',function(data){
$.each(data,function(index,entry){
//assuming we already have a <div> created and get the id
//show the JSON data
$('#div_id_created_earlier').append('
'Title: ' + entry.title + '<br />' +
'Start: ' + entry.start + '<br />' +
'End: ' + entry.end + '<br />' +
'All day: ' + entry.allDay + '<br /><br />' +
');
});
});