在其他选择 AJAX PHP 上进行更改时显示选择


showing select when make a change on other select ajax php

我有一个代码,我不知道我的问题是什么。我正在尝试从其他选择中打开另一个选择,并在新选择选项中获取旧的选择值,但我不能这样做,我不知道为什么。这是我的代码,我的页面我在其中编写了名为Mekha的代码.php :

  <html>
  <head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function showUser(str) {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("makhfe").style.display = "block";
            }
        }
        xmlhttp.open("GET","mekha.php?q="+str,true);
        xmlhttp.send();
}
</script>
</head>
<body>
<?php
if(isset($_GET["q"]))
{
echo $_GET["q"];
}
?>
<select id="firstselect" onchange="showUser(this.value)">
    <option value="1">One</option>
    <option value="2">Two</option>
</select>
<select style="display:none;" id="makhfe">
    <option value="1">One</option>
    <option value="2"><?=intval($_GET["q"])?></option>
</select>
</body>
</html>

请帮忙吗?

这样的事情应该可以工作:

 $("#firstselect").change(function() {
    value = $("#firstselect").val();
    data = {"value": value };
    $.post("server_ajax_link.php", data)
       .done(function(data) {
         new_data = data.new_value_from_server;
     });
    $("#makhfe").show();
    $("#makhfe[value='2']").text(new_data );
});

有关更简单的示例,您可以查看此处的文档: http://api.jquery.com/jquery.post/