ajax与struts2操作

1

$.ajax({url:'<%=request.getContextPath()%>/SysParam/selTitle.action',
async:false,
type:"get",
dataType:"json",
data:{"code":title,"rd":Math.random()},
success:function(data){
$("title").html(data.title);
}});

public void selTitle()
{
String code = getRequest().getParameter("code");
HttpServletResponse resp = getResponse();
resp.setContentType("text/html; charset=utf-8");
resp.setHeader("Cache-Control", "no-cache");
try {
Map map = new HashMap<String, Object>();
map.put("title", getText(code));
resp.getWriter().write(com.cms.common.utils.JSONUtil.formJSON(map));//JSONObject json = JSONObject.fromObject(map);
} catch (IOException e) {
LOG.error(e.getMessage());
}
}

2.通过ajax异步包含页面

$.ajax({url:'<%=request.getContextPath()%>/Role/bgcolumn.action',
async:true,
type:"get",
//dataType:"json",
data:{"rd":Math.random()},
success:function(data){
$("#submenuleft").html(data);
}});

你可能感兴趣的:(struts2)