Ajax read the content of the database implementation of the two-level linkage Drop-down Select Menu Sample _ajax Related

Source: Internet
Author: User
Copy Code code as follows:

<pre class=javascript name= "code" ></pre><pre class=javascript name= "code" > ————————————————————— This is Ajax (JavaScript) code ——————————————————————————— </pre><pre class=javascript name= "code" ></PRE> <pre class=javascript name= "code" >function Send_request (Callback, urladdress, Isreturndata) {
var xmlhttp = getxmlhttprequest ();
Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4) {//readystate is 4-data transfer end
try{
if (Xmlhttp.status = = 200) {
if (Isreturndata && isreturndata==true) {
Callback (Xmlhttp.responsetext);
}
}else{
Callback ("Sorry, did not find this page:" + urladdress + "");
}
catch (e) {
Callback ("Sorry, send request failed, please try again" + e);
}
}
}
Xmlhttp.open ("POST", urladdress, True);
Xmlhttp.send (NULL);
}
function Getxmlhttprequest () {
var xmlhttp;
if (window. XMLHttpRequest) {
try {
XMLHTTP = new XMLHttpRequest ();
Xmlhttp.overridemimetype ("Text/html;charset=utf-8");/set to identify data by UTF-8 encoding
catch (e) {}
else if (window. ActiveXObject) {
try {
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {
try {
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {
try {
XMLHTTP = new ActiveXObject ("Msxml3.xmlhttp");
catch (e) {}
}
}
}
return XMLHTTP;
}
</PRE> ———————————————————————— This is the client form JSP code —————————————————————————————— <BR>
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ taglib uri="/struts-tags "prefix=" s "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Content= "text/html; Charset=utf-8 "><title>insert title Here</title><script type=" Text/javascript "src=" <%= Request.getcontextpath ()%>/js/xmlhttp.js "></script><script type=" Text/javascript ">function" GetProcess (value) {var process = document.getElementById (' process '); Send_request (function (value2)
{process.innerhtml = value2;}, "Getprocesstype.action?value=" +value, True);} </script>Value= "G" > Management process </option><option value= "Z" > Support process </option></select><div id= "process" ><select name= "Smallclass" ><option value= "first-level process name" Selected> Please select a first-level process name </OPTION></select> </div><input type= "Submit" value= "submitted" ></form></div></body><PRE></PRE>
<BR>
<p><pre class=html name= "code" ><pre class=html name= "code" > ———————————————————————— This is the service-side action code —————————————————————————————— </PRE><BR>
<P></P>
<PRE></PRE>
Here's my business logic, and each logic is different, so this code is just to put what you want to display in the request range, and then return to the next page. JavaBean has my myprocess class and its properties
<P></P>
<p><pre Class=java name= "code" >public String Getprocesstype () {
HttpServletRequest request=servletactioncontext.getrequest ();
String value=request.getparameter ("value");
List<myprocess> myprocesses= Processservice.getprocessbytype (value);
for (myprocess p:myprocesses) {
System.out.println (P.getname ());
}
Request.setattribute ("list", myprocesses);
return SUCCESS;
}</pre><pre class=html name= "code" ></pre><pre class=html name= "code" ></pre><pre class=html name= "Code" > ———————————————————————— This is the service-side JSP code —————————————————————————————— </pre><pre class=html name= "code" ><%@ page language= "java" contenttype= "text/html"; Charset=utf-8 "
pageencoding= "UTF-8"%>
<%@ include file= "/page/share/taglib.jsp"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<select name= "Smallclass" >
<option value= "First-level process name" Selected> Please select the first process name </OPTION>
<c:foreach items= "${list}" var= "Myprocess" >
<option value= "${myprocess.processid}" >
${myprocess.name}
</option>
</c:forEach>
</select>
</body>
<BR>
<P></P>
<P> the process is pretty much the same! </P>
<P><BR>
</P>
</PRE>
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.