sinosoft
var select = "<select id='transferCatalog"+(parseInt(index)+1)+"' name='transferCatalog"+(parseInt(index)+1)+"' οnchange='onChangeHandleCatalog(this, this.value,"+(parseInt(index)+1)+")'>";
select += "<option value=''>-请选择-</option>";
if (value != "") {
var retValue = $.ajax({
async:false,
type: "POST",
url: "opine-query!getCatalogsByNodeParent.action",
data: "nodeParent=" + value+"&node="+index,
success: function(msg){
//alert( "Data Saved: " + msg );
}
}).responseText;
//alert("retValue" + retValue);
if(retValue == ""){
alert("获取分类信息失败。");
return;
}
// 解析json对象
var dataObj = eval("("+retValue+")");
$.each(dataObj,function(idx,item){
select += "<option value='" + item.CATALOG + "'>"+ item.NODE_NAME +"</option>";//sql查的字段
});
}
select += "</select>";
$(selectObj).after(select);
OpineQueryAction里面。
/**
* 根据上级分类获取下一级分类信息
*/
public void getCatalogsByNodeParent() {
try {
List<Map<String, Object>> catalogList = opinionManager.getCatalogByNodeParent(nodeParent,node);
//获取HttpServletResponse,将用户登录信息返回前台
HttpServletResponse response = ServletActionContext.getResponse();
response.getWriter().print(JSONArray.fromObject(catalogList).toString());
} catch (Exception e) {
e.printStackTrace();
}
}
无刷新页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
var xmlhttp;
function createRequest(){
if(window.ActiveXObject){
xmlhttp=new ActiveXObject("msxml2.xmlhttp");
}else{
xmlhttp=new XMLHttpRequest();
}
}
function init(){
createRequest();//1
xmlhttp.onreadystatechange=function(){//2
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
t=xmlhttp.responseText;
document.getElementById("pr").innerHTML=t;
}
}
}
xmlhttp.open("GET", "<%=basePath%>ajax.jsp", true);
xmlhttp.send(null);
}
function zhaocity(xx){
alert(xx);
}
</script>
</head>
<body οnlοad="init();">
<form>
请选择省<div id="pr"><select name="province" id="province">
<option id="0">--请选择省--</option>
</select></div>
</form>
</body>
</html>
代理页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.bluedot.jclg.dao.EmpDAO"%>
<%@page import="com.bluedot.jclg.vo.Areas"%>
<%
EmpDAO dao=new EmpDAO();
String fid=request.getParameter("fid");
StringBuffer sb=new StringBuffer("<select name='province' id='province' οnchange='zhaocity(this.value)'><option>--ppp--</option>");
//if(fid!=null){
Set<Areas> s=dao.query(0);
Iterator it=s.iterator();
while(it.hasNext()){
Areas a=(Areas)it.next();
sb.append("<option value="+a.getId()+">"+a.getName()+"</option>");
}
sb.append("</select>");
out.println(sb.toString());
out.flush();
//}
%>