修改PHP文件使用jQuery $ .post

I'm trying to add a value from a selected in my html into a PHP file using jQuery. I have 2 php file, chainmenu.php and function.php. function.php contain 2 functions to get some data from my database. chainmenu.php is used to show the result of a function from function.php. It requires a variable, that is a value from selected option in my html. I was able to retrieve the value, but my problem is that my $.post function doesn't work. I dont know where is the error, is it in my chainmenu.php or in my function.php.

This is my code

jQuery CODE

  <script type="text/javascript">
        $(document).ready(function() {
            $("select#trafo").attr("disabled","disabled");
            $("select#gi").change(function(){
                $("select#trafo").attr("disabled","disabled");
                $("select#trafo").html("<option>wait...</option>");
                var id = $("select#gi option:selected").attr('value');
                $("select#trafo").html("<Option>"+id+"</Option>");
                $.post("chainmenu.php", {id:id}, function(data){
                    $("select#trafo").removeAttr("disabled");
                    $("select#trafo").html(data);
                });
            });
        });
        </script>

Function.php

 <?php class SelectList
    {

//$this->conn is working fine here

    public function ShowGI()
            {
                $sql = "SELECT * FROM gi";
                $res = mysqli_query($this->conn,$sql);  
                if(mysqli_num_rows($res)>=1){
                    $category = '<option value="0">Pilih GI</option>';
                    while($row = mysqli_fetch_array($res))
                    {
                        $category .= '<option value="' . $row['idgi'] . '">' . $row['namegi'] . '</option>';
                    }
                }
                return $category;
            }

            public function ShowIt()
            {
                $sql = "SELECT * FROM It WHERE idgi=$_POST[id]";
                $res = mysql_query($sql,$this->conn);
                $type = '<option value="0">Choose/option>';
                while($row = mysql_fetch_array($res))
                {
                    $type .= '<option value="' . $row['idIt'] . '">' . $row['name'] . '</option>';
                }
                return $type;
            }
               }

    $opt = new SelectList();
    ?>

chainmenu.php

<?php include "/opsi.class.php";
echo $opt->ShowIt(); ?>

HTML Code

<head>
<!-- the script here -->
</head>
<body>
<select id=gi>
<option value="0"> Select </option>
</select>
<select id=It>
<!-- chainmenu.php result should be here -->
</select>

</body>

This explanation a little bit messy, but i hope anyone could help me and give me some good advice.

Thank you.

try like this in chainmenu.php

<?php include "/opsi.class.php";
echo $opt->ShowIt($_POST['id']); ?>

in function.php replace ShowIt() method like below,

public function ShowIt($id)
            {
                $sql = "SELECT * FROM It WHERE idgi=$id";
                $res = mysql_query($sql,$this->conn);
                $type = '<option value="0">Choose/option>';
                while($row = mysql_fetch_array($res))
                {
                    $type .= '<option value="' . $row['idIt'] . '">' . $row['name'] . '</option>';
                }
                return $type;
            }

There are a few typos in ShowIt() function for e.g $type = '<option value="0">Choose/option>'; the tag isn't closed properly. In the jquery code you are retrieving the value and adding the html to select tag having id trafo. whereas in html code the id of the select is It.

<select id=It>
 <!-- chainmenu.php result should be here -->
</select>