简体   繁体   English

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

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

How to pass datepicker value to PHP without reloading the HTML page using XMLHttpRequest(); 如何在不使用XMLHttpRequest()重新加载HTML页面的情况下将datepicker值传递给PHP。 I am using this date value for further query and displaying in the same html page. 我正在使用此日期值进行进一步查询,并显示在同一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"];
    }
?>

I believe the function parameter str is giving you the date value you selected if yes, then you are missing the header information for content-type. 我相信函数参数str为您提供了选择的日期值(如果是),那么您就缺少内容类型的标题信息。 Please set it as follow after xmlhttp.open("POST", "chart.php" , true); 请在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.

相关问题 如何在不重新加载页面的情况下将数据javascript传递到php页面 - how to pass data javascript into php page without reloading the page 如何在不重新加载页面的情况下将信息传递给并运行PHP脚本 - How to pass information to and run a PHP script without reloading the page 如何使用html中的php将文本框的值保存到.txt文件,而无需重新加载或重定向页面? - How to save the value of a textbox to a .txt file using php in html without reloading or redirecting the page? 如何在不使用ajax重新加载页面的情况下将javascript值放入php变量中 - How to get javascript value into php variable without reloading the page using ajax 如何在不重新加载页面的情况下使用AJAX将表单值发送到php? - how to send form values to php using AJAX without reloading page? 将当前HTML文本框值从JavaScript传递到PHP,而无需重新加载页面或写入URL - Pass current HTML textbox value from JavaScript to PHP without reloading the page or writing to the URL 如何在不重新加载页面的情况下将数据从 HTML 页面传递到 PHP 脚本? - How to pass data from HTML page to PHP script without reloading the page? 如何在不重新加载页面的情况下运行php函数 - how to run php function without reloading the page 提交表单后如何清除表单并将数据传递到php文件而不重新加载页面 - how to clear form after submit the form and pass the data to php file without reloading page 使用JQUERY重新加载div而不重新加载页面 - Reloading a div without reloading a page using JQUERY
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM