A robust and practical Ajax two-level linkage menu (with demo and source package download)
The main code is as follows:
Index.asp
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" C/>
<title>ajax level two linkage by AH PK </title>
<script language= "javascript" src= "Js.js" ></script>
<body>
<!--#include file= "iconn.asp"-->
<%
Set Afeng = Conn.execute ("Select Bigclassid,bigclassname from Bigclass")
%>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<div id= "Bigclass" style= "Float:left" >
<select name= "Select" >
<option value= "0" > Select a class </option>
<%if not Afeng. Eof Then
Do as not Afeng. Eof
Bigclassid= Afeng ("Bigclassid")
Bigclassname = Afeng ("Bigclassname")%>
<option value= "<%=bigclassid%>" ><%=bigclassname%></option>
<%afeng. Movenext
Loop
End If
Afeng. Close
Set Afeng = Nothing
Conn.close
Set Conn = nothing%>
</select>
</div>
<div id= "Subclass" style= "Float:left" ><select name= "Select2" >
<option value= "0" > select Class Two Category </option>
</select>
</div>
</form>
</body>
getsubcategory.asp file:
Copy Code code as follows:
<%
response.charset= "GB2312" sets the original character set to default to Utf-8
Bigclassid=safe (Request. QueryString ("Bigclassid")) ' illegal character filtering
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 "Illegal parameters"
Response.End
End If%>
<!--#include file= "iconn.asp"-->
<%on Error Resume Next
Set P = Conn.execute ("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 = "<select name= ' Smallclassid ' >" &vbnewline
Do as not p.eof
html = html& "<option value=" &p ("Smallclassid") & "' >" &p ("Smallclassname") & "</option > "&vbnewline
P.movenext
Loop
html = html& "</select>"
Else
html = "<select name= ' smallclassid ' ><option value= ' 0 ' selected> no small category </option></select>"
End If
P.close
Set p = Nothing
Conn.close
Set Conn = Nothing
Response.Write html
html = ""
End If
%>
iconn.asp file:
Copy Code code as follows:
<%
Set Conn=server. CreateObject ("Adodb.connection")
db = "$ #yeahdown. com@$$$@@%%.asp"
C & Server.MapPath (db)
On Error Resume Next
Conn.Open ConnStr
If ERR Then
Err.Clear
Response.Write "<div id=" "Error" > Connection Database error </div>
Response.End
End If
Function Safe (STR)
If Isnull (STR) Then
Safe = ""
Exit Function
End If
STR = Replace (STR,CHR (0), "", 1,-1, 1)
str = Replace (str, "" "," "", 1,-1, 1)
str = Replace (str, "<", "<", 1,-1, 1)
str = Replace (str, ">", ">", 1,-1, 1)
str = Replace (str, "script", "script", 1,-1, 0)
str = Replace (str, "script", "script", 1,-1, 0)
str = Replace (str, "script", "script", 1,-1, 0)
str = Replace (str, "script", "script", 1,-1, 1)
str = Replace (str, "Object", "Object", 1,-1, 0)
str = Replace (str, "Object", "Object", 1,-1, 0)
str = Replace (str, "Object", "Object", 1,-1, 0)
str = Replace (str, "Object", "Object", 1,-1, 1)
str = Replace (str, applet, applet, 1,-1, 0)
str = Replace (str, applet, applet, 1,-1, 0)
str = Replace (str, applet, applet, 1,-1, 0)
str = Replace (str, applet, applet, 1,-1, 1)
str = Replace (str, "[", "[")
str = Replace (str, "]", "]")
str = Replace (str, "" "", "", 1,-1, 1)
str = Replace (str, "=", "=", 1,-1, 1)
str = Replace (str, "'", "" ", 1,-1, 1)
str = Replace (str, "select", "select", 1,-1, 1)
str = Replace (str, "Execute", "execute", 1,-1, 1)
str = Replace (str, "exec", "exec", 1,-1, 1)
str = Replace (str, "join", "join", 1,-1, 1)
str = Replace (str, "union", "union", 1,-1, 1)
str = Replace (str, "where", "where", 1,-1, 1)
str = Replace (str, INSERT, INSERT, 1,-1, 1)
str = Replace (str, "delete", "delete", 1,-1, 1)
str = Replace (str, "Update", "Update", 1,-1, 1)
str = Replace (str, "like", "like", 1,-1, 1)
str = Replace (str, "Drop", "drop", 1,-1, 1)
str = Replace (str, "create", "create", 1,-1, 1)
str = Replace (str, "rename", "Rename", 1,-1, 1)
str = Replace (str, "Count", "Count", 1,-1, 1)
str = Replace (str, "CHR", "Chr", 1,-1, 1)
str = Replace (str, "Mid", "mid", 1,-1, 1)
str = Replace (str, "truncate", "truncate", 1,-1, 1)
str = Replace (str, "nchar", "nchar", 1,-1, 1)
str = Replace (str, "char", "char", 1,-1, 1)
str = Replace (str, "ALTER", "Alter", 1,-1, 1)
str = Replace (str, "cast", "cast", 1,-1, 1)
str = Replace (str, "exists", "exists", 1,-1, 1)
STR = Replace (STR,CHR), <br>, 1,-1, 1)
Safe = Replace (Str, "'", "" ", 1,-1, 1)
End Function
%>
One last js.js.
Copy Code code as follows:
function Createxmlhttp ()
{
Xmlhttpobj = false;
try{//create objects, one by one, hey, if you can unify the standard all right.
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 Class Two </option></select> ";
Return
};
var xmlhttpobj = Createxmlhttp ();
if (xmlhttpobj) {//If the object Xmlhttpobj successfully created
Xmlhttpobj.open (' Get ', ' getsubcategory.asp?bigclassid= ' +bigclassid+ ' &number= ' +math.random (), true);//get method Add a random number.
Xmlhttpobj.send (NULL);
Xmlhttpobj.onreadystatechange=function () {//Client monitoring functions
if (xmlhttpobj.readystate==4) {//server processing request complete
if (xmlhttpobj.status==200) {
Alert (' OK ');
var html = xmlhttpobj.responsetext;//Get return value
document.getElementById ("Subclass"). innerhtml=html;
}else{
document.getElementById ("Subclass"). Innerhtml= "Sorry, there is a problem with the page you requested ...";
}
}else{
document.getElementById ("Subclass"). Innerhtml= "In the load, please wait ...";//server processing
}
}
}
}
Package file Download