2014-12-06 61 views
0

我正在使用fullcalendar来显示mysql数据库中的事件。事件呈现在我的events.php页面中,fullcalendar从events.php中显示json提要。我正在尝试创建一个报表/表单提交页面,该页面将显示与特定日期的fullcalendar相同的信息。如何根据datepicker选项从json feed获取事件

问题是我似乎没有正确地请求日期,因为无论我选择哪个日期,它都会给出完全相同的数据。最终我会在页面上使用日期选择器来选择日期,但现在我只是试图在代码中手动插入日期。无论我选择哪一天,它都会给我相同的结果。这是我用来从events.php请求数据的脚本

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
    jQuery('#datepicker_1').change(function(){ 
     jQuery.post('events.php', 'view=person&start=2014-12-07'+'&end=2014-12-08', function(data){ 
      alert(data[0].id); 

      });  
    }); 
}); 
</script> 

目前它给了我完全相同的数据,不管我选择什么日期。

+0

您没有选择用于查询选定的日期。请分享HTML代码作为关于如何选择日期的建议。你可以通过$(element).val()获得日期的值 – 2014-12-06 16:06:49

+0

我不知道你在说什么。你能详细说明吗? – 2014-12-07 12:38:22

回答

0

在你的代码中,你从来没有改变参数开始start=2014-12-07和结束&end=2014-12-08 paramater。

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
    jQuery('#datepicker_1').change(function(){ 
     jQuery.post('events.php', 'view=person&start=2014-12-07'+'&end=2014-12-08', function(data){ 
      alert(data[0].id); 

      });  
    }); 
}); 
</script> 

根据您提供的URL,events.php接受日期范围而不仅仅是日期。假设你只是为'end'参数选择一个日期,并为'start'参数减去一天,你可以在这里使用这个伪代码。

$("#datepicker").datepicker({ 
    dateFormat: "yy-mm-dd", 
    onSelect: function(strDate){ 
     //Instantiate endDate from strDate 

     //Assign a value to startDate by subtracting a day from endDate 

     //Preformat post data from endDate and startDate 

     //Send an ajax call using the preformatted data and handle the response 
    } 
}); 

希望这有助于

+0

我明白你在说什么的想法,但我不知道如何做到这部分 //实例结束日期从strDate //从结束日期 减去每天分配一个值的startDate //从endDate和startDate预格式化发布数据 //使用预先格式化的数据发送ajax调用并处理响应 – 2014-12-07 12:39:24