我将对我的问题做出一种解释: 尝试将 fullcalendar 集成到通过 mysql 和 ajax 获取数据的网络上,我想仅在日历上显示预订日期,如果它与一个“房子”相关,特别是当单击此房子时。 所以,在我的 php 中我收到 $pisoid = $_GET['piso'];然后我在同一页面中使用 js 脚本,并通过 post ajax 传递该数据:
var pisoid = "<?php echo $pisoid; ?>" ;
$.ajax({
url: 'process.php',
type: 'POST', // Send post data
data: 'type=fetch',
async: false,
success: function(s){
json_events = s;
}
});
我也用这个:
$('#calendar').fullCalendar({
events: JSON.parse(json_events),
//events: [{"id":"14","title":"New Event","start":"2015-01-24T16:00:00+04:00","allDay":false}],
utc: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true,
slotDuration: '00:30:00',
eventReceive: function(event){
var title = event.title;
var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
$.ajax({
url: 'process.php',
data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone+'&pisoid='+pisoid,
type: 'POST',
dataType: 'json',
success: function(response){
event.id = response.eventid;
$('#calendar').fullCalendar('updateEvent',event);
},
error: function(e){
console.log(e.responseText);
}
});
$('#calendar').fullCalendar('updateEvent',event);
console.log(event);
});
然后,在我的 process.php 上我尝试制作:
$space = $_POST['pisoid'];
$events = array();
$query = mysqli_query($con, "SELECT * FROM calendar where pisoid='$space'");
while($fetch = mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$e = array();
$e['id'] = $fetch['id'];
$e['title'] = $fetch['title'];
$e['start'] = $fetch['startdate'];
$e['end'] = $fetch['enddate'];
$allday = ($fetch['allDay'] == "true") ? true : false;
$e['allDay'] = $allday;
array_push($events, $e);
}
echo json_encode($events);
在我的sql查询中我放了一个数字而不是$space,一切都好,但是在这个$space中我没有收到正确的数字,那么我该如何制作这个东西???
最佳答案
您将数据传递为 fullcalendar 函数中的 URL 更改此:
data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone+'&pisoid='+pisoid,
致:
data: {type: 'new', title: title, startdate: start, zone: zone, pisoid: pisoid}
像这样,您将不同的变量(类型、标题等)传递给您在 PHP 文件中使用的超全局变量。
说明: 数据数组的构造如下:'nameofattribute':变量 JavaScript 将负责创建 URL/发布数据
您的问题是您尝试使用 POST 变量获取正在传递的数据的“GET”参数(我可能不会添加 key )。尝试切换它们,应该会有所帮助
关于php - 我如何通过ajax将$_GET传递给另一个php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34815905/