我正在使用fullcalendar.js,并且日历正在运行,因为它现在应该是。如果用户点击日历中的条目,则模式会显示一些信息。我现在需要的是,模式中的信息是来自数据库的信息,所以我想插入一些PHP代码,但我不知道如何。将PHP代码转换为Javascript
让我告诉你,我想用这样从我的数据库中的数据在模式显示的PHP代码:
<?php
$dates=getPcalInfoOfHour($gl_userid,0,0);
for ($x=0;$x<count($dates["id"]);$x++) {
Title: '".$dates["title"][$x]."';
Selected Date: '".$dates["date"][$x]."';
Selected Time: '".$dates["start"][$x]."' '".$dates["end"][$x]."';
Topic: '".$dates["topic"][$x]."';
Location: '".$dates["location"][$x]."';
Address: '".$dates["address"][$x]."';
}
?>
这里就是我想进入我的JavaScript代码的一部分我的PHP代码:
eventClick: function(calEvent, jsEvent, view) {
//display a modal
var modal =
'<div class="modal fade">\
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-body">\
<button type="button" class="close" data-dismiss="modal" style="margin-top:-10px;">×</button>\
<label> <strong>Topic:</strong> Topic</label>\
<label> <strong>Selected Dated:</strong> Date</label>\
<label> <strong>Selected Time:</strong> Time</label>\
<label> <strong>Title:</strong> Title</label>\
<label> <strong>Location:</strong> Location</label>\
<label> <strong>Address:</strong> Address</label>\
<label> <strong>Phone:</strong> Phone</label>\
</div>\
<div class="modal-footer">\
<button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> Close Window</button>\
</div>\
</div>\
</div>\
</div>';
var modal = $(modal).appendTo('body');
modal.modal('show').on('hidden', function(){
modal.remove();
});
console.log(calEvent.id);
console.log(jsEvent);
console.log(view);
}
我知道PHP是一个服务器端语言和JavaScript是基于客户端的语言,但必须有一个办法,从数据库中我的数据会模态内可以显示我是正确的?我对PHP编程有一点了解,但我从来没有用JavaScript写过东西。
如果有人能告诉我我的代码应该是什么样子,以便从模式窗口中的数据库中获取我的信息,我将非常感激。
谢谢, 克里斯
你可以写像'变种PHP ='和'alert(php)'我认为它的工作 –
如果数据被用户填满,您很容易受到XSS攻击。 – GuyT
[JavaScript中的访问PHP变量](http:// stackoverflow。com/questions/4287357/access-php-variable-in-javascript) – moonwave99