0

我正在使用这个网站上的 JQuery eventcalendar 插件。

有谁知道我如何将变量发送到 JSON,以便过滤输出的数据。我可以在链接中发送它还是需要使用 AJAX?任何指针将不胜感激。提前致谢。

<div id="cal"></div>

$("#cal").eventCalendar({
  // link to events json
  eventsjson: 'file.php' 
});

文件.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);
    }
}
4

1 回答 1

2

这个插件的代码有:

$.getJSON(eventsOpts.eventsjson + "?limit="+limit+"&year="+year+"&month="+month+"&day="+day, function(data)...

这意味着如果您向链接添加参数,它将无法正常工作......

您需要稍微更改插件代码以测试参数是否存在,然后才添加内部参数,例如:

var URL = eventsOpts.eventsjson;
URL += (eventsOpts.eventsjson.indexOf('?') < 0) ? '?' : '&';
URL += "limit="+limit+"&year="+year+"&month="+month+"&day="+day;
$.getJSON(URL, function(data)... 
于 2012-09-18T11:40:45.283 回答