将答案发送到服务器,并从服务器检索相关的数组以备下一个输入选项


send answer to server, and retrieve relevant array from server back for next input options

我正试图让以下内容发挥作用:我想将下拉菜单问题的答案发送到php脚本,这反过来会给我从数据库中返回一个新的选择。然后我想使用这个新的选择来更改辅助下拉菜单中的可用输入选项

最终目标是通过提供初步限制(选择你的市政当局),将选择范围从大约200个(日托中心)限制到大约15个

供参考的"gem(eente)"是市

到目前为止,我所拥有的javascript/ajax部分是这样的:

function loadXMLDoc(str) {
      var xmlhttp;
      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("gemeente").innerHTML=xmlhttp.responseText;
                 }
           }
      xmlhttp.open("POST","http:www.doenwatikkan.nl/jeroen/dynamic.php",true);
      xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xmlhttp.send(gem);
      alert(gem)
           }

php部分就是这个

<?php
include 'dbconnection.php';
$gem=$_POST["gem"];
$gennam=mysql_query("SELECT * FROM psz WHERE Gemeente='$gem'");
echo "ik ben in dit php script geweest";
$test="willekeurige string";
?>

相关的html/php部分如下:

<select name="pszplaats" id="gemeente" onchange="fdisplay();loadXMLDoc(this.value)">
    <?php while($row=mysql_fetch_array($selectgem)){?>
    <option value="<?php echo $row['Gemeente']; ?>"><?php echo $row['Gemeente'];?>
    </option>
     <?php } ?>
    </select>
    <select name="psznaam" id="test" style="display:none">
    <?php while($row=mysql_fetch_array($gennam)){?>
    <option value="<?php echo $row['NaamPSZ']; ?>"><?php echo $row['NaamPSZ'];?>
    </option>
     <?php } ?>
    </select>

javascript中的alert(gem)部分是有效的,所以如果人们选择了一个minucuality选项,它会显示在屏幕上,但php部分的"echo"没有显示任何内容,所以我认为ajax没有正确地查看我的php。

谁能告诉我我犯了什么愚蠢的错误吗?因为我搞不清楚。提前感谢!

我刚刚对后面的PHP脚本发出了一个快速请求,它正在输出echo-fine的内容。

xmlhttp.open("POST","http:www.doenwatikkan.nl/jeroen/dynamic.php",true);

上面的URL在"http:"之后似乎缺少"//",我想您的浏览器将向"current_URL/http:www.…"发出请求,这当然是行不通的。