The use of ajax jquery to achieve secondary interaction menu

  • 2020-03-30 00:42:03
  • OfStack

Menu resources are stored in the database. Ajax implementation using jquery. Json-lib-2.2.3-jdk15.jar ezmorph-1.0.6.jar json.js jquery.js

JSP page code:
<%@ page contentType="text/html; charset=gbk"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/json.js"></script> 
<% String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; 

<script type="text/javascript"> 
function onchangeShow(oneId){ 
url : "<%=basePath%>cateJson.whbs", 
data : {parentId : oneId}, //  parameter  
type : "post", 
cache : false, 
dataType : "json", //Return json data
error: function(){ 
function onchangecallback(data){ 
document.all['twoId'].options.length = 0; //Clear the old options
var str=""; 
for(var i=0;i<data.length;i++){ 
str+="<option value='"+data[i].recordId+"'>"+data[i].title+"</option>" 
<div align="center"> 
 Please select the department type  
<s:select list="rfones" listKey="recordId" listValue="title" name="oneId" theme="simple" id="oneId" value="oneID" onchange="onchangeShow(this.value)"></s:select> 

 Please select the file type  
<s:select list="rftwos" listKey="recordId" listValue="title" name="twoId" theme="simple" id="twoId" value="twoID"></s:select> 

The code for the action in struts
public String getJsonCategory() throws IOException{ 
rfjsons=archiveService.getCategoryByParentID(parentId);//Here we get the data from the database
net.sf.json.JSONArray jsonObj=net.sf.json.JSONArray.fromObject(rfjsons);//Assemble the json data
sendMessage(jsonObj.toString());//Push json data to the view
return null; 
public void sendMessage(String content) throws IOException{ 
HttpServletResponse response = ServletActionContext.getResponse(); 


Related articles: