Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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
Php 动态依赖形式_Php_Jquery_Html_Mysql_Ajax - Fatal编程技术网

Php 动态依赖形式

Php 动态依赖形式,php,jquery,html,mysql,ajax,Php,Jquery,Html,Mysql,Ajax,我想为预订脚本制作一个动态的依赖表单。 在第一个输入字段中,日期和时间将由客户填写。 在表单的第二部分,有一个下拉列表,它将提供可用的(未预订的)房间 如果希望页面使用仅对服务器可用的信息对用户输入做出反应,则需要使用AJAX。在vanilla javascript中执行此操作的方法是创建一个XMLHttpRequest对象(在每个现代broswer中都实现),向服务器发送一个请求,然后侦听答案,当得到答案时,可以相应地更新选项 简单演示 var xhttp = new XMLHttpReque

我想为预订脚本制作一个动态的依赖表单。 在第一个输入字段中,日期和时间将由客户填写。 在表单的第二部分,有一个下拉列表,它将提供可用的(未预订的)房间


如果希望页面使用仅对服务器可用的信息对用户输入做出反应,则需要使用AJAX。在vanilla javascript中执行此操作的方法是创建一个XMLHttpRequest对象(在每个现代broswer中都实现),向服务器发送一个请求,然后侦听答案,当得到答案时,可以相应地更新选项

简单演示

var xhttp = new XMLHttpRequest();
xhttp.open("GET", "getbookings.php", true);
//You can send information here to the $_GET or $_POST variable in php
xhttp.send("I love hotels");

//And to listen to the answer
xhttp.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200) {
        console.log(this.responseText);
    }
};
onreadystatechange事件在请求状态更改时触发,4表示请求已完成。与200不同的状态意味着服务器出现了问题,所以请记住检查!至于php文件应该做什么,只需打印一个包含所需信息的纯文本或JSON字符串,这样就可以用javascript解析它


作为附录,您可以在

上阅读更多内容,较新的浏览器还可以支持FetchAPI(),它是XMLHttpRequest的继承者(最终!)。
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "getbookings.php", true);
//You can send information here to the $_GET or $_POST variable in php
xhttp.send("I love hotels");

//And to listen to the answer
xhttp.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200) {
        console.log(this.responseText);
    }
};