使用ajax和vbscript选择1个组合框作为依赖组合框时出错

时间:2022-10-16 07:28:46

i m using 2 dependent combobox in my page. when i select value from 1st combobox (by default it is "select state"), in 2nd combobox value is displaying correct and working fine but when i select again "select state" option(with no value) in 1st combobox then its showing alert saying "there was a problem while using XMLHTTP. internal server error" instead of showing "select city" option(with no value) in 2nd combobox. please help me out to solve this issue.

我在我的页面中使用2个依赖的组合框。当我从第一个组合框中选择值时(默认情况下它是“选择状态”),在第二个组合框中显示正确且工作正常,但是当我在第一个组合框中再次选择“选择状态”选项(没有值)时,它显示警告说“使用XMLHTTP时出现问题。内部服务器错误”而不是在第二个组合框中显示“select city”选项(没有值)。请帮我解决这个问题。

here is my ajax script

这是我的ajax脚本

<script language="javascript" type="text/javascript">
function getXMLHTTP() { 
var xmlhttp=false;  
try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e)    {       
        try{            
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
}

    return xmlhttp;
}

function getcity(stateId) {     

    var strURL="findcity.asp?state="+stateId;
    var req = getXMLHTTP();

    if (req) {

        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {                        
                      document.getElementById('citydiv').innerHTML=req.responseText;                        
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }               
        }           
        req.open("GET", strURL, true);
        req.send(null);
    }       
}

</script>

here is my code for populate state

这是我填充状态的代码

<select name="state_name" onChange="getcity(this.value)">

i have added value="0" in Select State

我在选择状态中添加了值=“0”

<option value="0">Select State</option> ' edited
<%while not Objrs_state.eof%>
<option value="<%=Objrs_state("ASId")%>"><%=Objrs_state("ASName")%></option>
<%Objrs_state.movenext
wend
Objrs_state.close
set Objrs_state = nothing
set objCmd_state = nothing%>
    </select>

for populate city

适合居住的城市

<span id="citydiv"><select name="city" >
<option>Select City</option>
    </select></span>

here is findcity.asp code

这是findcity.asp代码

<select name="city">
<% Do While Not Objrs_city.EOF %>
<option value="<%= objrs_city("ACId")%>"><%= Objrs_city("ACName")%></option>
<%
Objrs_city.MoveNext
Loop
%>
    </select>

1 个解决方案

#1


0  

Most Probably, you have a query in the findcity.asp page where you are appending the state id to the query in that page.

最常见的是,您在findcity.asp页面中有一个查询,您要将状态ID附加到该页面中的查询。

Try changing the state dropdown html:

尝试更改状态下拉列表html:

<select name="state_name" onChange="getcity(this.value)">
<option >Select State</option>
....

To:

<select name="state_name" onChange="getcity(this.value)">
<option value="0">Select State</option>

That is, give a value of 0 to the first option

也就是说,给第一个选项赋值为0

w.r.t to your comment, to show select city add an initial option to the dropdown in findcity.asp

w.r.t对你的评论,显示选择城市为findcity.asp中的下拉列表添加一个初始选项

<select name="city">
<option value="0">select city</option>
<% Do While Not Objrs_city.EOF %>
....

#1


0  

Most Probably, you have a query in the findcity.asp page where you are appending the state id to the query in that page.

最常见的是,您在findcity.asp页面中有一个查询,您要将状态ID附加到该页面中的查询。

Try changing the state dropdown html:

尝试更改状态下拉列表html:

<select name="state_name" onChange="getcity(this.value)">
<option >Select State</option>
....

To:

<select name="state_name" onChange="getcity(this.value)">
<option value="0">Select State</option>

That is, give a value of 0 to the first option

也就是说,给第一个选项赋值为0

w.r.t to your comment, to show select city add an initial option to the dropdown in findcity.asp

w.r.t对你的评论,显示选择城市为findcity.asp中的下拉列表添加一个初始选项

<select name="city">
<option value="0">select city</option>
<% Do While Not Objrs_city.EOF %>
....