繁体   English   中英

如何在不使用XMLHttpRequest()重新加载页面的情况下将datepicker值传递给php;

[英]How to pass datepicker value to php without reloading the page using XMLHttpRequest();

如何在不使用XMLHttpRequest()重新加载HTML页面的情况下将datepicker值传递给PHP。 我正在使用此日期值进行进一步查询,并显示在同一html页面中。

<input type="date" id="month" onchange="myFunction(this.value)">
<script>
    function myFunction(str) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("month").value = this.responseText;
            }
        };
        xmlhttp.open("POST", "chart.php", true);
        xmlhttp.send("value=" + str);
    }
</script>

<?php
    $date = "";
    if(isset($_POST["value"])){
        $date =  $_POST["value"];
    }
?>

我相信函数参数str为您提供了选择的日期值(如果是),那么您就缺少内容类型的标题信息。 请在xmlhttp.open("POST", "chart.php" , true);之后设置如下xmlhttp.open("POST", "chart.php" , true);

xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM