2015-04-30 55 views
1

我從envato市場購買了這個jQuery mobile calender插件,我遇到的問題是它沒有檢測到我生成的PHP JSON數據。 這是我的PHP代碼:jquery mobile calender plugin not loading json data

<?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

您是否嘗試過使用.done而不是.then,這只是一個承諾,所以它沒有多大意義。 – devconcept

回答

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); 
?> 
+0

我試過它沒有工作,我認爲這個問題是更多的JSON數據,它可能是日曆的JavaScript, –

+0

然後嘗試回顯工作的JSON,你從上面張貼從PHP –

+0

不仍然working.your解決方案是正確的我認爲這是日曆javascript;我得到(Uncaught TypeError:無法讀取未定義的屬性'getTime')。 –