使用API​​ JSON根据第一个下拉列表填充第二个下拉列表 [英] Populate 2nd drop-down list based on 1st drop-down using API JSON

查看:75
本文介绍了使用API​​ JSON根据第一个下拉列表填充第二个下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于从第一个下拉列表中选择的数据在第二个下拉列表中显示数据.我使用AJAX在第二个下拉列表中获取显示数据.

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.

如果facID = F09,则下面是JSON结果

Below is the JSON result if facID = F09

下面是下拉列表所在的AJAX代码

Below is the AJAX code at where the drop-down list is located

<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>   

下面是room_scheduler.php

and below is the 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>";
            }

        }

    ?>

如果在第一个下拉列表中选择F09,则第二个下拉列表中没有数据显示时的结果.我能知道是什么问题吗?

The result if, if in the 1st drop-down list I choose F09, there's no data display at the 2nd drop-down list. 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>";
            }

        }


    ?>

这篇关于使用API​​ JSON根据第一个下拉列表填充第二个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆