如何从php获取数据并将其传递到另一个oojs
问题描述:
我想实现什么? - >我需要从sql中追加值标题和url。如何从php获取数据并将其传递到另一个oojs
$('#calendar').fullCalendar({
defaultDate: '2017-06-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
"title": "Click for Google",
"url": "http://google.com/",
"start": "2017-06-28"
}]
我试过了吗? - >
$.ajax({
type: 'GET',
url: 'eventcalendar.php',
dataType:'JSON',
success: function(response) {
console.log(response[0]);
return response;
}
});
我得到了什么? - >
{"title":"Example","start":"2017-06-21","end":"2017-06-
22","url":"http:\/\/www.facebook.com"}{"title":"Holiday","start":"2017-06-
23","end":"2017-06-24","url":"http:\/\/www.google.com"}
我的PHP代码: - >
<?php
error_reporting(0);
include 'announcements/db.php';
$sql = mysql_query("select title, start, end, url from eventcalendar");
$num_rows = mysql_num_rows($sql);
$userinfo = array();
while ($row_user = mysql_fetch_assoc($sql)) {
$userinfo[] = $row_user;
}
echo json_encode($userinfo);
?>
我需要从MySQL获得的价值和更新的事件中:使从SQL所有的标题标签会显示
*我是一个新手,这是我的第一个代码。如果您有更好的选择,请提供帮助和建议。万分感谢 !!
答
我假设您使用的是FullCalendar库。
除了不推荐使用的mysql_ *函数,我认为你对ajax的用法有些困惑。
成功函数只有在ajax解析并且响应成功时才会触发。所以,你可以考虑两种不同的方法是:
1 - 初始化您的日历,当您收到响应数据:
$.ajax({
type: 'GET',
url: 'eventcalendar.php',
dataType:'JSON',
success: function (response) {
$('#calendar').fullCalendar({
defaultDate: '2017-06-12',
editable: true,
eventLimit: true,
events: response
});
}
});
2 - 刷新日历事件当AJAX解决。在这种情况下,你可以使用FullCalendar内置的方法:
success: function (response) {
$('#calendar').fullCalendar('updateEvents', response);
}
希望我帮助,祝你好运:)
+0
非常感谢。像魅力一样工作..你是对的。我对此感到困惑不已。感谢您的注意和解释... –
*我是一个新手,这是我的第一个代码*浏览PHP手册,那么你将了解到'mysql_ *'函数已折旧并不再受支持 –
@MasivuyeCokile感谢您的信息。你能帮助上面的代码吗? –