$.ajax({ //加$符表示用jquery,可以不加
url:basePath+"system/area/xx.action",//路径
type: 'POST',//传输方式
dataType: 'TEXT',//数据类型
data:param,//传输的数据 例如 param={a,"1";b,"2"}
timeout: -1,//超时时间
beforeSend: function(request){
request.setRequestHeader("RequestType","AJAX");
},
complete:function(){
},
error: function(){
alert('获取信息失败');
},
success: function(html){ //htm是成功返回的数据
var data = eval("("+$.trim(html)+")"); //去空格
if(data.retCode!=0){ //获取返回的参数
return;
}
}
});
action代码
WebAppComposer client = (WebAppComposer) request.getSession().getAttribute("client"); HttpServletResponse response = ServletActionContext.getResponse();//获取response对象 response.setCharacterEncoding("utf-8"); //设置编码格式 response.setContentType("text/xml;charset=utf-8"); PrintWriter out=response.getWriter(); //获取out对象 if (client == null) { request.setAttribute("error","您的会话已过期,请重新登陆!"); } try { String xmmc=request.getParameter("xmmc"); //获取穿过来的参数 xmmc=xmmc!=null?xmmc:""; String flag=xmbbdjService.queryXmmc(xmmc); String code=""; code+=flag; System.out.println(code); if(flag.equals("0")){ out.print("{retCode:0}"); //返回的参数 }else{ out.print("{retCode:-1}"); } }catch(Exception e){ e.printStackTrace(); }