我从envato市场购买了这个jQuery移动日历插件,我遇到的问题是它没有检测到我生成的PHP生成的JSON数据。 这是我的PHP代码:
<?php
$output = ' {"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")},
{"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")},
{"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")},
';
echo ($output);
?>
这是我的JavaScript
$( document ).ready(function() {
var date1 = new Date();
var date2 = new Date();
var date3 = new Date();
var date4 = new Date();
var date5 = new Date();
var date6 = new Date();
var date7 = new Date();
var date8 = new Date();
var date9 = new Date();
date1.setDate(date1.getDate() - 30);
date2.setDate(date2.getDate() - 15);
date3.setDate(date3.getDate() - 13);
date4.setDate(date4.getDate() - 3);
date5.setDate(date5.getDate() + 5);
date6.setDate(date6.getDate() + 6);
date7.setDate(date7.getDate() + 12);
date8.setDate(date8.getDate() + 30);
date9.setDate(date9.getDate() + 38);
//var calEvents = "http://localhost/indicium/admin/data/app-calender.php";
var root = 'http://localhost/indicium/admin/data/app-calender.php';
$.ajax({
url: root,
method: 'GET',
//dataType: 'JSONP'
}).then(function(data) {
initCalendar(data);
});
function initCalendar(data) {
alert(data);
$("#calendar").jqmCalendar({
events : data,
months : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
days : ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
startOfWeek : 1
});
}
});
我对javascript检测数据(json)有什么帮助,我尝试通过提醒它成功提醒的数据进行调试,但是在我的浏览器控制台中我看到了这个(Cannot read property 'getTime' of undefined
);
请帮忙。
这里是日历javascript json数据有效吗
var calEvents = [
{"icon": "bars","eid":"1","title":"My event test","url":"#","start":new Date("2014-02-10T08:00:00.000Z"),"end":new Date("2014-02-10T10:00:00.000Z"),"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":" 1","title":"My event test","url":"#","start":new Date("2014-02-10T17:00:00.000Z"),"end":new Date("2014-02-10T18:00:00.000Z"),"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":"1","title":"My event 1","url":"#","start":date1,"end":date1,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"icon": "info","eid":"2","title":"Event testing 2","url":"#","start":new Date("2015-04-03 18:54:00.000000"),"end":date3,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":"3","title":"My event 3","url":"#","start":date4,"end":date4,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"icon": "alert","eid":"SomeID 4","title":"My event 4","url":"#","start":date5,"end":date6,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":"SomeID 5","title":"Just testing the calendar","url":"http://www.example.com","start":date7,"end":date7,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":"SomeID 6","title":"My event 6","url":"#","start":date8,"end":date8,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
{"eid":"SomeID 7","title":"My event 7","url":"#","start":date9,"end":date9,"discription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet sem risus. Curabitur vehicula lacus eu tincidunt interdum."},
];
答案 0 :(得分:0)
在json数据的末尾缺少[]和不需要的逗号。使用此:
<?php
$output = ' [{"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")},
{"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")},
{"eid":"1","title":"just event test","image":"1426791253.png","discription":"Montes, sociosqu voluptate ultrices, conubia eiusmod? Beatae illum. Mattis, vestibulum aenean integer quasi nisi convallis egestas tristique id, nunc impedit. Eligendi magni, curae eligendi! Tempor purus sit sequi gravida dolor.","url":"","start":new Date("2015-02-22 14:00:00"),"end":new Date("2015-02-25 13:00:00")}]';
echo ($output);
?>