dongwopu8210 2015-12-08 14:40
浏览 48

PHP5中的Ajax - 使用其他下拉列表更新下拉列表

I'm trying to update drop down list with the other drop down list using Ajax. Somehow it is not working. I'm not sure which path is going wrong.

php file

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
    function AjaxFunction(cat_id)
    {
    var httpxml;
    try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
        try
                   {
                httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                }
           catch (e)
                {
             try
            {
            httpxml=new ActiveXObject("Microsoft.XMLHTTP");
            }
             catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
          }
  }
function stateck() 
    {
    if(httpxml.readyState==4)
      {

var myarray=eval(httpxml.responseText);
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);
}


for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcat.options.add(optn);

} 
      }
    }
   var url="dd2.php";
url=url+"?cat_id="+cat_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
  }
</script>


<title>tresn</title>
</head>


<table width="1021" border="0" style="top:0;left:0; position:fixed">
  <tr>
    <td height="25"><form action='Test3.php?mula=0&amp;akhir=12' method="POST" class="dropdown_button" name="testform" id="form1">
      <strong> 
        Sort By:
        <select name="cat" onchange="AjaxFunction(this.value);" id="SortBy">
          <option value="0">(Short By)</option>
          <?php
$q=mysqli_query($db,"select * from db_prd_category ");
while($n=mysqli_fetch_array($q)){
echo "<option value=$n[Cat_Id]>$n[Name]</option>";
}
?>
        </select>
        <select name="subcat">
        </select>
        <input type="submit" class ="small button yellow" name="Filter" id="Filter" style="height:25px" value="Filter" />
        &nbsp; </strong>
    </form></td>
  </tr>
</table>`

Ajax file

<?php
$cat_id=$_GET['cat_id'];
require "config.php";

$q=mysqli_query($db,"Select * from db_prd_subcategory where Cat_Id='$cat_id' ORDER BY  SubCat_Id ASC");
echo mysqli_error();
$myarray=array();
$str="";

while($n=mysqli_fetch_array($q)){
$str=$str . "\"$nt[Name]\"".",";
}

$str=substr($str,0,(strLen($str)-1)); 
echo "new Array($str)";

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器