ajax讀取資料庫內容實現二級聯動下拉選擇菜單樣本_AJAX相關

來源:互聯網
上載者:User
複製代碼 代碼如下:

<PRE class=javascript name="code"></PRE><PRE class=javascript name="code">—————————————————————這是ajax(javascript)代碼———————————————————————————</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 為4即資料轉送結束
try{
if(xmlhttp.status == 200){
if(isReturnData && isReturnData==true){
callback(xmlhttp.responseText);
}
}else{
callback("抱歉,沒找到此頁面:"+ urladdress +"");
}
} catch(e){
callback("抱歉,發送請求失敗,請重試 " + 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");//設定以UTF-8編碼識別資料
} 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>————————————————————————這是用戶端表單jsp代碼——————————————————————————————<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"><html><head><meta http-equiv="Content-Type"
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></head><body><div><form action="" method="post" name="form"><select name="process" onchange="getProcess(this.value)"><option value="0" selected>請選擇流程種類</option><option value="Y">商務程序</option><option
value="G">管理流程</option><option value="Z">支援流程</option></select><div id="process"><select name="smallclass"><option value="一級流程名稱" selected>請選擇一級流程名稱</OPTION></select></div><input type="submit" value="提交"></form></div></body></html>
<PRE></PRE>
<BR>
<P><PRE class=html name="code"><PRE class=html name="code">————————————————————————這是服務端action代碼——————————————————————————————</PRE><BR>
<P></P>
<PRE></PRE>
這裡是我的商務邏輯,每個邏輯不同,所以這段代碼這隻是為了把想要顯示的內容放在request範圍內,然後return到下一個頁面.javabean中有我的MyProcess類和它的屬性
<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">————————————————————————這是服務端jsp代碼——————————————————————————————</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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<select name="smallclass">
<option value="一級流程名稱" selected>請選擇一級流程名稱</OPTION>
<c:forEach items="${list}" var="myprocess">
<option value="${myprocess.processID}" >
${myprocess.name}
</option>
</c:forEach>
</select>
</body>
</html></PRE><BR>
<BR>
<P></P>
<P>這個過程差不多就這些!</P>
<P><BR>
</P>
</PRE>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.