我有三个 HTML DropDownList(下拉列表)()。第一个 DropDownList 包含类别,第二个包含不同产品的子类别,第三个包含品牌(或制造商)。
当选择一个类别时,根据传递给Ajax函数的类别ID,应该立即从数据库中填充两个下拉列表子类别和品牌。我正在使用以下Ajax代码。
当选择一个类别时,会调用
它正在工作,根据传递的类别id(它是上述函数
我不必要地在
为什么会发生这种情况?有什么解决办法?
当选择一个类别时,根据传递给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(selected)
Javascript函数来进行Ajax请求。问题在于,我需要同时填充子类别和品牌下拉框(当选择一个类别时)。它正在工作,根据传递的类别id(它是上述函数
selected
的参数)同时填充两个下拉框。我不必要地在
getBrandList()
函数底部使用了一个警告框。当这个警告框被注释掉时,只有一个下拉框——子类别被填充,品牌保持为空。我不再需要这个警告框。为什么会发生这种情况?有什么解决办法?