[英]Populate 2nd drop-down list based on 1st drop-down using API JSON
I want to display data at 2nd drop-down list base on data chosen from 1st drop-down list.我想根据从第一个下拉列表中选择的数据在第二个下拉列表中显示数据。 I used AJAX to get display data at 2nd drop downlist.
我使用 AJAX 在第二个下拉列表中获取显示数据。
Below is the JSON result if facID = F09下面是 facID = F09 时的 JSON 结果
Below is the AJAX code at where the drop-down list is located下面是下拉列表所在的 AJAX 代码
<script>
function getroom(val) {
$.ajax({
type: "POST",
url: "../room_scheduler/room_scheduler.php",
data:'factory_id='+val,
success: function(data){
$("#room-list").html(data);
}
});
}
</script>
and below is the room_scheduler.php下面是 room_scheduler.php
<?php
require_once "../../../config/configPDO.php";
require_once "../../../config/check.php";
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/roomList?facID='" . $_POST['factory_id'] . "'";
$data = file_get_contents($url);
$characters = json_decode($data);
if(!empty($_POST["factory_id"])) {
echo '<option value="">Select</option>';
foreach ($characters->roomList as $character) {
echo "<option value='$character->roomId'>$character->Room_Desc</option>";
}
}
?>
The result if, if in the 1st drop-down list I choose F09, there's no data display at the 2nd drop-down list.结果,如果在第一个下拉列表中我选择 F09,则在第二个下拉列表中没有数据显示。 Can I know what is the problem?
我能知道是什么问题吗?
Sorry guys, this question already solved by myself对不起各位,这个问题我已经解决了
<?php
require_once "../../../config/configPDO.php";
require_once "../../../config/check.php";
$factory_id = $_POST["factory_id"];
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/roomList?facID=$factory_id";
$data = file_get_contents($url);
$characters = json_decode($data);
if(!empty($factory_id)) {
echo '<option value="">Select</option>';
foreach ($characters->roomList as $character) {
echo "<option value='$character->roomId'>$character->roomDesc</option>";
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.