Php 如何在代码点火器中显示从控制器到满炉的数据
这是我的控制器Php 如何在代码点火器中显示从控制器到满炉的数据,php,jquery,ajax,codeigniter,fullcalendar,Php,Jquery,Ajax,Codeigniter,Fullcalendar,这是我的控制器 function Test_Function() { // Event id; // event.title is the only place where you can "display" text; // event.start: What date should the event be placed $data = array ( array ( 'id' =>
function Test_Function()
{
// Event id;
// event.title is the only place where you can "display" text;
// event.start: What date should the event be placed
$data = array
(
array
(
'id' => 1234,
'title' => "Mr Name xxxxx\nDate 2016-06-04T00:00:00\nBirthday\nemail sasa@asfda.com\nTelephone 1234567890",
'start' => "2016-06-15"
),
);
// add more array(...events...) as required
echo json_encode($data);
}
我需要使用ajax在完整的日历中显示这些细节,以及如何显示结果
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
url: '<?php echo site_url('Air/Get_calander_fare'); ?>',
type: 'POST',
data: {
value1: 'aaa',
value2: 'bbb'
},
success: function(data) {
console.log(data);
},
error: function() {
alert('there was an error while fetching events!');
},
}
});
});
$(文档).ready(函数(){
$(“#日历”).fullCalendar({
活动:{
url:“”,
键入:“POST”,
数据:{
值1:‘aaa’,
价值2:‘bbb’
},
成功:功能(数据){
控制台日志(数据);
},
错误:函数(){
警报('获取事件时出错!');
},
}
});
});
我需要显示$Data日期中的姓名、数据、电子邮件和电话,而不是使用
echo$Data
使用return$Data
自动返回所需的值。在PHP过程中,您必须回显json编码的字符串或任何其他字符串,而不是字符串。AJAX需要字符串,而您的字符串格式不好。您可以手动键入example.tld/[index.php/]controller\u name/test\u function
(方括号部分是为了防止您在apache中设置重写规则)的URL来检查它,并查看什么是回显或输出。如果你在Ubuntu中有解析错误,默认情况下可以在/var/log/apache2/error.log
中检查,但如果需要,你可以在/etc/php5/apache2/php.ini中检查并重新配置。位置取决于您的操作系统。您应该将$data
字符串用单引号括起来,而不是用双引号括起来。有效输出如下所示:
$data = '{"Results":{"Results":[{"Title":"Mr","Name":"xxxxx","Date":"2016-06-04T00:00:00","Data":"Birthday","email":"sasa@asfda.com","Telephone":1234567890},{"Title":"Mr","Name":"yyyyy","Date":"2016-06-05T00:00:00","Data":"Birthday","email":"qwee@rrrrr.com","Telephone":7412589630},{"Title":"Mrs","Name":"zzzzzzz","Date":"2016-06-07T00:00:00","Data":"Anniversary","email":"asdaf@qwe.com","Telephone":1234567890}]}}';
echo $data;
您有两个选项可以让您的数据显示在日历中,您的事件数据必须根据文档进行格式化。和中介绍了这两个选项
我将用php格式化数据,并使用事件作为json,因为对我来说这更简单,但是它需要更改Test\u函数()
。您可以通过以下方式获得Test\u Function()
echo数据:
function Test_Function()
{
// Event id;
// event.title is the only place where you can "display" text;
// event.start: What date should the event be placed
$data = array
(
array
(
'id' => 1234,
'title' => "Mr Name xxxxx\nDate 2016-06-04T00:00:00\nBirthday\nemail sasa@asfda.com\nTelephone 1234567890",
'start' => "2016-06-06"
),
);
// add more array(...events...) as required
echo json_encode($data);
}
然后在jQuery中
作为JSON提要(旁注:您缺少事件的封闭}:{…)
更新
我正在使用FullCalendar v2.7.3和jQuery v2.1.4。下面是我用来获取事件的代码
php中的测试函数()
<?php
Test_Function();
function Test_Function()
{
// Event id;
// event.title is the only place where you can "display" text;
// event.start: What date should the event be placed
$data = array
(
array
(
'id' => 1234,
'title' => "Mr Name xxxxx\nDate 2016-06-04T00:00:00\nBirthday\nemail sasa@asfda.com\nTelephone 1234567890",
'start' => "2016-06-06"
),
);
// add more array(...events...) as required
echo json_encode($data);
}
?>
在html中。根据设置更改事件url
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='../fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../fullcalendar.min.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
url: './php/test-function.php',
type: 'POST',
data: {
value1: 'aaa',
value2: 'bbb'
},
success: function(data) {
console.log(data);
},
error: function() {
alert('there was an error while fetching events!');
},
}
});
});
</script>
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
$(文档).ready(函数(){
$(“#日历”).fullCalendar({
活动:{
url:“./php/test function.php”,
键入:“POST”,
数据:{
值1:‘aaa’,
价值2:‘bbb’
},
成功:功能(数据){
控制台日志(数据);
},
错误:函数(){
警报('获取事件时出错!');
},
}
});
});
身体{
利润率:40像素10像素;
填充:0;
字体系列:“Lucida Grande”,Helvetica,Arial,Verdana,无衬线;
字体大小:14px;
}
#历法{
最大宽度:900px;
保证金:0自动;
}
您可以在eventRendar函数中附加json数据
eventRender:函数(事件,元素){
元素.find('.fc content').parent().append(''+event.name+'');
}
可能会有帮助我正在使用相同的东西,但我发现在获取事件时出现了错误!@vellaidurai我已更新了我的答案,以包括我用于事件和日历的代码。请查看它,并让我知道它是否适用于您。我已更新了我现在在问题中使用的内容。我仍然收到了相同的错误。有一个错误在获取事件时!
$('#calendar').fullCalendar({
events: function(start, end, timezone, callback) {
$.ajax({
url: '<?php echo site_url('Test/Test_Function'); ?>',
type: 'POST',
data: {
value1: 'aaa',
value2: 'bbb'
},
success: function(data) {
var events = [];
/* loop though all the events received from php and parse them and push them into an array
var event = {
id = data[index]
events.push(...);
*/
callback(events);
},
error: function() {
alert('there was an error while fetching events!');
},
});
}
});
<?php
Test_Function();
function Test_Function()
{
// Event id;
// event.title is the only place where you can "display" text;
// event.start: What date should the event be placed
$data = array
(
array
(
'id' => 1234,
'title' => "Mr Name xxxxx\nDate 2016-06-04T00:00:00\nBirthday\nemail sasa@asfda.com\nTelephone 1234567890",
'start' => "2016-06-06"
),
);
// add more array(...events...) as required
echo json_encode($data);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='../fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../fullcalendar.min.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
url: './php/test-function.php',
type: 'POST',
data: {
value1: 'aaa',
value2: 'bbb'
},
success: function(data) {
console.log(data);
},
error: function() {
alert('there was an error while fetching events!');
},
}
});
});
</script>
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
eventRender: function (event, element) {
element.find('.fc-content').parent().append('<span>'+event.name+'</span>');
}