Two-level linkage menu based on asp + ajax and database driver. The code for copying the index. asp page code is as follows :! --#Includefileconn.asp--0000set0000conn.exe cute (selectbigclassid, bigclassnamefrombigclass) tempbigclassid) % index. asp page code
The code is as follows:
<%
Set cmd = conn.exe cute ("select bigclassid, bigclassname from bigclass ")
Tempid = cmd ("bigclassid ")
%>
<%If not cmd. eof thenDo while not cmd. eofBigclassid = cmd ("bigclassid ")Bigclassname = cmd ("bigclassname ")%><% = Bigclassname %> <%Cmd. movenextLoopEnd ifCmd. closeSet cmd = nothing%>
<%Set cxd = conn.exe cute ("select * from smallclass where bigclassid =" & tempid)If not cxd. eof thenDo while not cxd. eofSmallclassid = cxd ("smallclassid ")Smallclassname = cxd ("smallclassname") %><% = Smallclassname %> <%Cxd. movenextLoopCxd. closeSet cxd = nothingElseHtml ="No small category"
Response. write html
End if
%>
Ajax. js code
The 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 Level 2";
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
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 =""& VbnewlineDo while not p. eofHtml = html &""& P (" smallclassname ")&""& VbnewlineP. movenextLoopHtml = html &""
Else
Html ="No small category"
End if
P. close
Set p = nothing
Conn. close
Set conn = nothing
Response. write html
Html = ""
End if
%>
The http://www.bkjia.com/PHPjc/321638.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321638.htmlTechArticleindex.asp page code is as follows :! -- # Include file = "conn. asp" -- % set cmd = conn.exe cute ("select bigclassid, bigclassname from bigclass") tempid = cmd ("bigclassid") %...