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

Javascript 如何在不使用XMLHttpRequest()重新加载页面的情况下将datepicker值传递给php;,javascript,php,html,ajax,Javascript,Php,Html,Ajax,如何在不使用XMLHttpRequest()重新加载HTML页面的情况下将datepicker值传递给PHP; 我使用此日期值进行进一步查询,并显示在同一html页面中 <input type="date" id="month" onchange="myFunction(this.value)"> <script> function myFunction(str) { var xmlhttp = new 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"];
    }
?>

函数myFunction(str){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“月”).value=this.responseText;
}
};
open(“POST”,“chart.php”,true);
xmlhttp.send(“value=“+str”);
}

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


如果条件以布尔值形式给出false,则该值不会传递到php页面。我也不知道str是否有价值。Html和脚本代码在同一页,php在另一页我检查了您的代码。str正确地得到了它的值,您只需要按照建议添加我在答案中传递的行。这对我有用。
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');