Javascript 如何将xmlhttp.responseText插入到已经存在的下拉html元素中?
目标:我想从Connection.php代码段上的getFaculties()中检索值,并将它们插入表单上的Javascript 如何将xmlhttp.responseText插入到已经存在的下拉html元素中?,javascript,php,html,Javascript,Php,Html,目标:我想从Connection.php代码段上的getFaculties()中检索值,并将它们插入表单上的 我表格中的一段代码 校名 教员姓名 这是执行请求的函数 函数dropUpdate(){ if(window.XMLHttpRequest){ xmlhttp=新的XMLHttpRequest(); }否则{ xmlhttp=newActiveXObject('Microsoft.xmlhttp'); } xmlhttp.onreadystatechange=函数(){ if(xm
我表格中的一段代码
校名
教员姓名
这是执行请求的函数
函数dropUpdate(){
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=newActiveXObject('Microsoft.xmlhttp');
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById('selFaculty')。innerHTML=xmlhttp.responseText;
}
};
var ghgh=document.getElementById('selvarityName').value;
open('GET','Middle.php?selVarsityName='+ghgh,true);
xmlhttp.send();
}
这是Middle.php页面上的代码
require./Connection.php';
if(isset($\u GET['selVarsityName'])){
$selVarsityName=$\u GET['selVarsityName'];
$conn->getFaculties($selVarsityName);
}
my Connection.php页面上的代码
函数getVarsities(){
$query=“从“tb_大学”中选择*”;
$result=mysqli\u查询($this->link,$query);
如果($结果){
呼应“选择大学”;
而($row=mysqli\u fetch\u数组($result,mysqli\u ASSOC)){
$VarsityName=$row['university_name'];
回显“$VarsityName”;
}
}否则{
回显“未找到记录”;
}
}
函数getFaculties($ff){
$uni_id=0;
$query=“从`tb\u university`中选择`university\u id`,其中`university\u name`='$ff';
$result=mysqli\u查询($this->link,$query);
如果($结果){
而($row=mysqli\u fetch\u数组($result,mysqli\u ASSOC)){
$uni_id=$row['university_id'];
}
}
$query1=“从'faculty'中选择'faculty\u name',其中'university\u id`=$uni\u id';
$result1=mysqli\u查询($this->link,$query1);
如果($result1){
而($row=mysqli\u fetch\u数组($result1,mysqli\u ASSOC)){
$fal_name=$row['faculty_name'];
echo;
}
}
}
您需要在
Middle.php
中设置$conn
。请在使用
代码段编辑器进行整理时删除
code@Barmar...Look我可以检索我想要的所有数据到表单中,问题是我不知道如何将这些数据放入…我可以将数据放入,它显示,我所需要知道的就是如何把它放进。。