第二个下拉列表应根据第一个下拉列表中的选择进行填充,但我在第二个下拉列表中得到值“未定义”。从 SQL Server 获取数据。查看 Google 开发工具,我可以看到当我单击第一个下拉列表中的某个项目时,ajaxfile.php 会正确执行查询。
索引文件
<!doctype html>
<?PHP
$server = "server";
$options = array( "UID" => "user", "PWD" => "pass", "Database" =>
"database");
$conn2 = sqlsrv_connect($server, $options);
if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true));
echo " ";
?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<section id="formaT2" class="formaT2 formContent">
<div class="row">
<div class="col-md-2 col-3 row-color remove-mob"></div>
<div class="col-md-5 col-9 bg-img" style="padding-left: 0;
padding-right: 0;">
<h1>Form</h1>
<div class="rest-text">
<div class="contactFrm">
<p class="statusMsg <?php echo
!empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p>
<form action="connection.php" method="post">
<div>machinery</div>
<select id="machinery">
<option value="0">--Please Select Machinery--</option>
<?php
// Fetch Department
$sql = "SELECT Machinery FROM T013";
$machanery_data = sqlsrv_query($conn2,$sql);
while($row = sqlsrv_fetch_array($machanery_data) ){
$machinery = $row['Machinery'];
// Option
echo "<option value='".$machinery."' >".$machinery."</option>";
}
?>
</div>
</select>
<div class="clear"></div>
<div>Sub Machinery</div>
<select id="sub_machinery">
<option value="0">- Select -</option>
</select>
<input type="submit" name="submit"
id="submit" class="strelka-send" value="Insert">
<div class="clear"> </div>
</form>
</div>
</div>
</div>
</div>
</section>
</script>