Asp+ajax Two-level linkage perfect Realization method

Source: Internet
Author: User

Asp+ajax Two-level linkage perfect Realization method

<!--#include file= "conn.asp Tutorial"-->
<!--
//--------------------------------------------------------
ASP Programming Network
Sp+ajax linkage two level linkage, reprint please keep this information
-->
<! 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" content= "text/html; charset=gb2312 "/>
<title>asp+ajax Two-level linkage </title>
<script language= "Web Effects" type= "Text/javascript" src= "Ajax.js" ></script>

<body>
<form name= "MyForm" action= "mylist.asp" method= "POST"
  <select name= "BId" Onchange= "Getoid (This.value,");
    <option value= "" > Please select Large class </option>
    <%
Dim ors,osql
Set oRs = server. CreateObject ("Adodb.recordset")
OSQL = "Select Id,otitle,opx from news_cls Where oId = 0 ORDER by opx ASC"
Ors.ope n osql,conn,1,1
If (ors.eof and Ors.bof) Then
 response.write ("<option value=" "" "> did not add a large class </option > ")
Else
 do while ors.eof
  response.write (" <option value= "" "&ors (0) &" " ">" &ors (1) & "</option>")
 ors.movenext
 loop
End If
ORs.Close:Set oRs = Nothing
 %>
  </select>
  <span id= "Smclass" ></SPAN>
  < Input Name= "" type= "submit"   value= "submitted"/>
</form>
</body>

Ajax Code

/*--------------------------------------------------------------------
*
* Create a XMLHTTP instance
*return object is successfully created to return a XMLHTTP instance, otherwise it returns false
*
*--------------------------------------------------------------------
*/
function Createajax () {
var XMLHttp;
Try
{
XMLHttp = new ActiveXObject ("Microsoft.XMLHTTP"); How IE is created
}
catch (E)
{
Try
{
XMLHttp = new XMLHttpRequest (); How to create a browser such as FF
}
catch (E)
{
XMLHttp = false; Creation failed, return false
}
}
return XMLHttp; Return XMLHTTP Instance
}
//--------------------------------------------------------
ASP Programming Network
http://www.111cn.net/
Asp+ajax linkage two level linkage, reprint please keep this information
function Getoid (IDS,SID) {
var xmlHttp = Createajax ();
var urllink = ' list10.asp?oid= ' +ids+ ' &sid= ' +sid+ ' &n= ' +math.random () + ';
if (xmlHttp) {
Xmlhttp.open (' Get ', urllink,true);
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate = = 4) {//client complete request
if (Xmlhttp.status = = 200) {//server-side completes processing and returns data
var responsetext = Xmlhttp.responsetext;
if (ResponseText = = "") {//service returned the error message
Alert ("Yes");
smclass.innerhtml = ResponseText;
}else{
Alert ("No");
smclass.innerhtml = ResponseText;
}
}else{
smclass.innerhtml = ' Server returns exception ... '//server exception
}
}else{
smclass.innerhtml = ' Loading data ... '//prompting information when request is incomplete
}
}
Xmlhttp.send (null);//Send request to Server
}else{
smclass.innerhtml = ' Your browser does not support or does not enable xmlhttp! ';//Creation unsuccessful
}
}

List10.asp

Response.Charset = "GB2312"
Dim Outstr,ors,osql
OID = Request ("oid")
Sid = Request ("Sid")
If (oid = "" Or IsNull (OID)) Then
outstr = ""
Else
outstr = "<select name=" "Smid" ">"
outstr = outstr & "<option value=" "0" "> Do not specify small class </option>"
OSQL = "Select Id,otitle,opx,oid from news_cls Where oId =" &oId& "
OSQL = OSQL & "ORDER by OPX ASC"
Set oRs = Conn.execute (OSQL)
If (ors.eof and Ors.bof) Then
outstr = outstr & "<option value=" "0" "> No small Class </option>"
Else
Do as not ors.eof
If trim (sId) = Trim (oRs (0)) Then
outstr = outstr & "<option value=" "&ors (0) &" "Selected>" &ors (1) & "</option>"
Else
outstr = outstr & "<option value=" "&ors (0) &" ">" &ors (1) & "</option>"
End If
Ors.movenext
Loop
End If
outstr = outstr & "</select>"
Set ORs = Nothing
End If
Response.Write (OUTSTR)

Conn.asp

Dim Mdb,conn,connstr
mdb= "Database/adsl.mdb"
Set Conn = Server.CreateObject ("ADODB. Connection ")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (MDB) & ""
Conn.Open ConnStr
Sub Closeconn ()
If IsObject (Conn) Then
Conn.close
Set Conn = Nothing
End If
End Sub

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.