在3个依赖框中,第3个框没有使用asp经典中的ajax和vbscript填充值

时间:2014-08-19 10:54:50

标签: javascript ajax vbscript asp-classic

我在asp经典页面中使用ajax和vbscript填充3(三重)依赖框。第1和第2箱工作正常。如果我在第一个框中选择STATE,则在第二个框中填充CITY列表,但是当我选择第二个框(CITY)时,在第三个框中没有填充CENTER列表。

我的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="findcity1.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);
    }       
}
function getCenter(StateId,CityId) {        
    var strURL="findCenter.asp?state="+stateId+"&city="+cityId;
    var req = getXMLHTTP();

    if (req) {

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

}

我填写STATES,CITY和CENTER的代码如下所示

<%
dim Objrs_state, str_state, objCmd_state
Set objCmd_state = Server.CreateObject("ADODB.Command")
Set Objrs_state   = Server.CreateObject("ADODB.Recordset")
str_state = "SELECT ASId, ASName FROM State_Name ORDER BY ASName Asc"
With objCmd_state
.ActiveConnection = MM_connDUdirectory_STRING
.CommandText = str_state
.CommandType = adCmdText
end with 
Objrs_state.open objCmd_state, , 1, 2
%>
<select name="statid" onChange="getcity(this.value)">
<option>Select State</option>
<%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>

'populating CITY as below given

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

'populating CENTER as below given

<span id="centerdiv"><select name="center">
<option>Select Center</option>
</select></span>

FindCity.asp

Set objCmd = Server.CreateObject("ADODB.Command")
Set Objrs   = Server.CreateObject("ADODB.Recordset")
str = "SELECT * FROM city_Name where ASId =? ORDER BY ACName Asc"
....
....
<select name="city" onChange="getcenter(stateID,this.value)">
<option>select city</option>
<% Do While Not Objrs.EOF %>
<option value="<%=objrs("ACId")%>"><%= Objrs("ACName")%></option>
<%
Objrs.MoveNext
Loop
%>
</select>

FindCenter.asp页面

Set objCmd = Server.CreateObject("ADODB.Command")
Set Objrs   = Server.CreateObject("ADODB.Recordset")
str = "SELECT * FROM Center_Detail where Center_state=? and Center_city=? ORDER BY Center_Name Asc"
....
....
<select name="center">
<option>select center</option>
<% Do While Not Objrs_center.EOF %>
<option value="<%=objrs_center("CnId")%>"><%= Objrs_center("Center_Name")%></option>
<%
Objrs_center.MoveNext
Loop
%>
</select>

第1和第2个框填充并且工作正常但是在与选择城市相关的第3个框中心列表中没有显示。请帮我解决这个问题。

0 个答案:

没有答案