 |
|
Code (JavaScript)
01. $.post( "<?=site_url(); ?>home/ajax_get_event" , { }, function (data) {
02. if (data.status == 'ok' )
03. {
04. var event_data = data.calendar_event;
05. alert(event_data);
06. } else {
07. }
08. }, "json" );
09. var calendar = $( "#calendar" ).calendar(
10. {
11. tmpl_path: "<?=site_url(); ?>themes/js/tmpls/" ,
12. events_source: event_data ,
13. onAfterViewLoad: function (view) {
14. $( '.page-header h3' ).text( this .getTitle());
15. $( '.btn-group button' ).removeClass( 'active' );
16. $( 'button[data-calendar-view="' + view + '"]' ).addClass( 'active' );
17. }
18. });
ตอนนี้ค่าที่ Ajax Return กลับมาหน้าตาแบบนี้ครับ
{"status":"ok","calendar_event":[{"id":"1","title":"Event Two","url":"http:\/\/demo.perfectconnection.co.th\/event\/detail\/1","class":"event-important","start":1446051600000,"end":1446051600000},{"id":"2","title":"Event Three","url":"http:\/\/demo.perfectconnection.co.th\/event\/detail\/2","class":"event-important","start":1446224400000,"end":1446224400000}]}
แต่ค่าที่ Alert ออกมาดูมันเป็น
[object Object],[object Object]
ตัวอย่างข้อมูลที่จะส่งเข้าไปหน้าตาประมาณนี้ครับ
[{"id":"1","title":"Event Two","url":"http:\/\/demo.perfectconnection.co.th\/event\/detail\/1","class":"event-important","start":1446051600000,"end":1446051600000},{"id":"2","title":"Event Three","url":"http:\/\/demo.perfectconnection.co.th\/event\/detail\/2","class":"event-important","start":1446224400000,"end":1446224400000}]
ทดลอง copy ไปวางตรงๆ ค่าที่ return มาไปวางใน events_source ตรงๆแสดงผลได้ครับแต่เรียกจากตัวแปรไม่ได้ รบกวนด้วยครับ
Jquery ที่ใช้นะครับ
https://github.com/Serhioromano/bootstrap-calendar
Tag : jQuery
|
ประวัติการแก้ไข 2015-11-06 16:49:56
|
 |
 |
 |
 |
Date :
2015-11-06 16:44:24 |
By :
zinlucifer |
View :
1218 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |