Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:如何让daterangepicker js变量在php文件php JAVASCRIPT中回音_Javascript_Php_Html - Fatal编程技术网

错误:如何让daterangepicker js变量在php文件php JAVASCRIPT中回音

错误:如何让daterangepicker js变量在php文件php JAVASCRIPT中回音,javascript,php,html,Javascript,Php,Html,我这里的问题是,当我尝试提交一个从开始到结束的日期范围时,它似乎无法在我的date2.php文件中显示值或变量,甚至在控制台日志(f12)中,控制台日志也只能读取“apply event fired..blablabla”。其他4个console.log也未被读取。 我不知道发生了什么 我在date2.php中的代码 <div class="x_content"> <div class="well" style="overflow: auto">

我这里的问题是,当我尝试提交一个从开始到结束的日期范围时,它似乎无法在我的date2.php文件中显示值或变量,甚至在控制台日志(f12)中,控制台日志也只能读取“apply event fired..blablabla”。其他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>";
?>

这对我有很大帮助。谢谢

我想我明白你的问题了。这应该可以解决它。当然,在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>

var startDate=“”; var endDate=“”; console.log(startDate+“:”+endDate); 书面文件(起始日期); 书面文件(截止日期);
不确定您在这里实际想做什么。首先,您使用Ajax发布帖子,然后成功重定向客户端?但它不是您重定向到的同一个文件(不同的URL)?然后在
date2.php
中,您试图在JS中控制台log
startdate
enddate
。你在那个页面上设置了那些js变量了吗?为什么还要使用PHP来响应它们呢?这段代码非常奇怪,它非常不清楚您实际上想做什么。这可能是对客户端(js)和服务器端(php)的误解。我还没有在php页面上设置它们,实际上我对js还不熟悉,所以你不能真正地用控制台记录它们是一个新的请求/页面。在PHP7中,您只需执行以下操作:
$startDate=$\u POST[''u startDate']。它与:
$startDate=isset($\u POST[''u startDate'])相同$_帖子[“开始日期]:”我知道,但作为一个例子,我的做法更具可读性。一般来说,如果需要,我会编写更多的代码,以便在性能不受影响的情况下更容易阅读。很难说,因为我不知道您的其他代码在做什么,而且我已经有一段时间没有使用jQuery日期选择器了。但是我提供的代码将把你的变量放到date2.php文件中,你可以在任何需要的地方使用它们。非常感谢。
<?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>