我的问题是,当我尝试提交一个从开始到结束的日期范围时,它似乎无法在date2.php文件甚至控制台日志中显示值或变量(仅在控制台日志中显示)。读取“已触发触发的应用事件。blabla”。其他4个console.log也不被读取。 我不知道发生了什么..
我在 date2.php
中的代码<div class="x_content">
<div class="well" style="overflow: auto">
<div class="col-md-4">
<div id="reportrange_right" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
</div>
</div>
</div>
<?php
echo "<script>document.writeln(startdate)</script>";
echo "<script>document.writeln(enddate)</script>";
?>
custom.js文件代码:
$('#reportrange_right').on('apply.daterangepicker', function(ev, picker) {
console.log("apply event fired, start/end dates are " + picker.startDate.format('MMMM D, YYYY') + " to " + picker.endDate.format('MMMM D, YYYY'));
var startdate = picker.startDate.format('MMMM D, YYYY');
var enddate = picker.endDate.format('MMMM D, YYYY');
console.log(startdate);
console.log(enddate);
console.log(picker.startDate.format('MMMM D, YYYY'));
$.post('date2.php', {
_startdate: startdate,
_enddate: enddate
}).done(function() {});
location.href = '../production/date2.php';
});
这对我有很大帮助。谢谢!
答案 0 :(得分:1)
我想我看到你的问题了。这应该解决它。当然,这应该带有关于是否在date2.php上正确加载所有js文件的所有警告。我无法在回答中说明所有这些问题。
<?php
//date2.php
$startDate = ""; //declaring start and end in case they come up empty in the if statement
$endDate = "";
if($_POST{'_startDate']){
//Strictly speaking you don't need to make these in to new variables
//It's just easier to use them later.
$startDate = $_POST['_startDate'];
$endDate = $_POST['_endDate'];
//Now you can put the posted variables where you need them.
}
?>
<!-- You can also just write in the variables anywhere you like -->
<p><?php echo $startDate;?></p> <!-- for example -->
<div class="x_content">
<div class="well" style="overflow: auto">
<div class="col-md-4">
<div id="reportrange_right" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
</div>
</div>
</div>
<script>
var startDate = '<?php echo $startDate; ?>';
var endDate = '<?php echo $endDate; ?>';
console.log(startDate + " : " + endDate);
document.writeIn(startDate);
document.writeIn(endDate);
</script>