Home  >  Article  >  Web Front-end  >  Using jquery's ajax to implement a two-level interactive menu_javascript skills

Using jquery's ajax to implement a two-level interactive menu_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:11:101160browse

Menu resources are saved in the database. Using jquery's ajax implementation. The packages used are: json-lib-2.2.3-jdk15.jar ezmorph-1.0.6.jar json.js jquery.js

JSP page code:

Copy code The code is as follows:

<%@ page contentType="text/html; charset=gbk "%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<% String basePath = request.getScheme() "://" request.getServerName() ":" request.getServerPort() request.getContextPath() "/";
out.println(basePath);
%>

< ;script type="text/javascript">
jQuery(function($){
//alert("ok");
});
function onchangeShow(oneId){
$.ajax({
url : "<%=basePath%>cateJson.whbs",
data : {parentId : oneId}, // Parameters
type : "post",
cache : false,
dataType : "json", //Return json data
error: function(){
alert('error');
},
success:onchangecallback
});
}
function onchangecallback(data){
document.all['twoId'].options.length = 0; //Clear the original options
var str=" ";
for(var i=0;istr =""
}
$("#twoId").html(str);
}




Please select the department type


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




Code of action in struts
Copy code The code is as follows:

/**
* des: Get the secondary linkage menu
* autho:exceljava
* date:Nov 20, 2009
* @return
* @throws IOException
*/
public String getJsonCategory() throws IOException{
rfjsons=archiveService.getCategoryByParentID(parentId);//Get data from the database here
net.sf.json.JSONArray jsonObj=net.sf.json.JSONArray.fromObject(rfjsons);//Assemble into json data
sendMessage(jsonObj.toString());//push json data to the view
return null;
}
/**
* des: encapsulates sending data in json format back to js
* autho:exceljava
* date:Nov 20, 2009
* @param content
* @throws IOException
*/
public void sendMessage(String content) throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.getWriter().write(content);

}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn