php ajax下拉列表,php – 使用Ajax一次填充两个下拉列表

我有三个

HTML DropDownList(< select>< option>< / option>< / select>).第一个DropDownList包含类别,第二个包含不同产品的子类别,第三个包含品牌(或制造商).

选择类别时,应根据传递给Ajax函数的类别ID,从数据库中一次填充两个下拉子类别和品牌.我正在使用以下Ajax代码.

function ajax()

{

if(window.XMLHttpRequest)

{

xmlhttp=new XMLHttpRequest();

}

else

{

xmlhttp = new ActivexObject("Microsoft.XMLHTTP");

}

}

function getBrandList(selected) //selected is the category id.

{

ajax();

xmlhttp.onreadystatechange=function()

{

if(xmlhttp.readyState==4 && xmlhttp.status==200)

{

document.getElementById("brandList").innerHTML=xmlhttp.responseText;

}

}

xmlhttp.open("GET","ajax/BrandAjax.php?selected="+selected, true);

xmlhttp.send();

alert(selected);

}

function getSubcategoryList(selected) //selected is the category id.

{

getBrandList(selected); //First above function is invoked to populate brands.

ajax();

xmlhttp.onreadystatechange=function()

{

if(xmlhttp.readyState==4 && xmlhttp.status==200)

{

document.getElementById("subCategoryList").innerHTML=xmlhttp.responseText;

}

}

xmlhttp.open("GET","ajax/SubCatAjax.php?selected="+selected, true);

xmlhttp.send();

}

选择类别时,将调用getSubcategoryList(选定)Javascript函数来执行Ajax请求.问题是我需要立即填充子类别和品牌下拉(当选择一个类别时).

它正在工作,并且根据传递的类别ID一次填充下拉列表(它是所选上述函数的参数).

我不必要地使用函数getBrandList()底部的警告框.注释此警报框时,只会填充一个子类别的下拉列表.品牌仍然是空的.我不再需要这个警报框了.

为什么会这样?解决办法是什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值