A robust and practical asp+ajax two-level linkage menu (with demo and source package download) _ Application Tips

Source: Internet
Author: User
Tags chr
A robust and practical Ajax two-level linkage menu (with demo and source package download)

Some days in the background of the time to use the two-level linkage of the menu, to the Internet to find a half-day also did not find satisfaction, not the fault is that wrong, in the choice of time sometimes can not return. It's depressing.
Later, I saw someone use Ajax to write an unlimited class (cow, hehe, I can not understand.). I think the backstage can not also use Ajax to try, although slower than using JavaScript, but I this practical. Strong. There will be no errors, and no large class will be selected to return to a state where no select state is empty. hehe.
File directory: as shown in

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.