0
我正在使用這個website的JQuery eventcalendar插件。使用jQuery插件發送變量到JSON
有沒有人知道我可以通過發送一個變量到JSON,所以我可以過濾輸出的數據。我可以在鏈接中發送它,還是需要使用AJAX?任何指針將不勝感激。 在此先感謝。
<div id="cal"></div>
$("#cal").eventCalendar({
// link to events json
eventsjson: 'file.php'
});
file.php
<?php
header('Content-type: text/json');
$var = $_GET["var"];
$sqldata = mysql_query('
SELECT
UNIX_TIMESTAMP(start_date) AS date,
employee AS title,
days AS description,
UNIX_TIMESTAMP(end_date) AS url
FROM requests WHERE approved = 1
');
$posts = array();
while($row = mysql_fetch_assoc($sqldata))
{
$row['date'] = $row['date'].'000';
$row['url'] = $row['url'].'000';
$row['description'] = $row['description'].' Days';
$posts[] = $row;
}
mysql_free_result($sqldata);
die(json_encode($posts));
?>
function getEvents(limit, year, month, day, direction) {
var limit = limit || 0;
var year = year || '';
var day = day || '';
// to avoid problem with january (month = 0)
if (typeof month != 'undefined') {
var month = month;
} else {
var month = '';
}
//var month = month || '';
flags.wrap.find('.eventsCalendar-loading').fadeIn();
if (eventsOpts.jsonData) {
// user send a json in the plugin params
eventsOpts.cacheJson = true;
flags.eventsJson = eventsOpts.jsonData;
getEventsData(flags.eventsJson, limit, year, month, day, direction);
} else if (!eventsOpts.cacheJson || !direction) {
// first load: load json and save it to future filters
$.getJSON(eventsOpts.eventsjson + "?limit="+limit+"&year="+year+"&month="+month+"&day="+day, function(data) {
flags.eventsJson = data; // save data to future filters
getEventsData(flags.eventsJson, limit, year, month, day, direction);
}).error(function() {
showError("error getting json: ");
});
} else {
// filter previus saved json
getEventsData(flags.eventsJson, limit, year, month, day, direction);
}
}
這是定義在一個單獨的.js,我將如何通過我的變量通過PHP到這個。我已經用定義的函數更新了這個問題 – Codded
我的意思是說插件代碼需要改變,所以它可以accpet你想傳遞給PHP的參數...... – Dror
:) ive使用你的方法對它進行排序,然後將參數添加到鏈接,將其添加到上面的JSON文件中,並調整jquery.eventCalendar.js以獲取新參數 – Codded