Index. asp page Code
Copy code The Code is as follows: <! -- # Include file = "conn. asp" -->
<%
Set cmd = conn.exe cute ("select bigclassid, bigclassname from bigclass ")
Tempid = cmd ("bigclassid ")
%>
<Select name = "menu" onchange = "getsubcategory (this. Value);">
<%
if not cmd. EOF then
do while not cmd. EOF
bigclassid = cmd ("bigclassid")
bigclassname = cmd ("bigclassname ")
%>
<% = bigclassname %>
<%
cmd. movenext
loop
end if
cmd. close
set cmd = nothing
%>
<%
set cxd = conn.exe cute ("select * From smallclass where bigclassid =" & tempid)
if not cxd. EOF then
do while not cxd. EOF
smallclassid = cxd ("smallclassid")
smallclassname = cxd ("smallclassname ") %>
<% = smallclassname %>
<%
cxd. movenext
loop
cxd. close
set cxd = nothing
else
html = " no small class "
response. write HTML
end if
%>
Ajax. JS CodeCopy codeThe Code is as follows: // JavaScript document
Function createxmlhttp ()
{
Xmlhttpobj = false;
Try {
Xmlhttpobj = new XMLHttpRequest;
} Catch (e ){
Try {
Xmlhttpobj = new activexobject ("msxml2.xmlhttp ");
} Catch (E2 ){
Try {
Xmlhttpobj = new activexobject ("Microsoft. XMLHTTP ");
} Catch (E3 ){
Xmlhttpobj = false;
}
}
}
Return xmlhttpobj;
}
Function getsubcategory (bigclassid ){
If (bigclassid = 0 ){
Document. getelementbyid ("subclass "). innerhtml = "<select name = 'smallclassid '> <option value = '0' selected> Select secondary category </option> </SELECT> ";
Return;
};
VaR xmlhttpobj = createxmlhttp ();
If (xmlhttpobj) {// if the object xmlhttpobj is created successfully
Xmlhttpobj. onreadystatechange = handle;
Xmlhttpobj. Open ('get', "getsubcategory. asp? Bigclassid = "+ bigclassid +" & number = "+ math. Random (), true); // Add a random number to the get method.
Xmlhttpobj. Send (null );
}
}
Function handle () {// client monitoring function
// If (xmlhttpobj. readystate = 4) {// The server completes processing the request
If (xmlhttpobj. Status = 200 ){
// Alert ('OK ');
VaR html = xmlhttpobj. responsetext; // obtain the returned value
Document. getelementbyid ("subclass"). innerhtml = HTML;
} Else {
Document. getelementbyid ("subclass"). innerhtml = "sorry, the requested page has a problem ...";
}
//}
// Else {
// Document. getelementbyid ("subclass"). innerhtml = xmlhttpobj. readystate; // the server is processing
//}
//}
}
getsubcategory. ASP code copy Code the code is as follows: <% @ Language = "VBScript" codePage = "936" %>
<%
response. charset = "gb2312"
bigclassid = safe (request. querystring ("bigclassid")
If bigclassid <> "" Then
set Re = new Regexp
re. ignorecase = true
re. global = false
re. pattern = "^ [0-9] {1, 3} $"
if not re. test (bigclassid) Then
response. write "invalid parameter"
response. end
end if %>
<% on error resume next
Set P = conn.exe cute ("select * From smallclass where bigclassid =" & bigclassid)
If err then
err. clear
response. write "query error"
response. end
end if
if not p. EOF then
html = "" & vbnewline do while not p. EOF html = HTML & "" & P ("smallclassname ") & "" & vbnewline P. movenext loop html = HTML & ""
else
html = " no small class "
end if
P. close
Set P = nothing
Conn. close
set conn = nothing
response. write HTML
html = ""
end if
%>