struts2 +jquery的ajax 怎么返回数据不做页面跳转
我用jquery的ajax访问action 但是按理说 返回数据的时候不应该做跳转页面 不刷新页面
这才是ajax的核心 但是现在每次返回都刷新 跳转页面
要怎么做啊? 不跳转页面 又能把数据返回到页面 实现无刷新取数据
我用jquery的ajax访问action 但是按理说 返回数据的时候不应该做跳转页面 不刷新页面
这才是ajax的核心 但是现在每次返回都刷新 跳转页面
要怎么做啊? 不跳转页面 又能把数据返回到页面 实现无刷新取数据
数据用 response.getWriter().write(content);
必要时转个码
中间不要<result></result>action类里面,方法写成void,不用return,返回的东西用response.gerWriter().print("..");
String[][] data = frontPub.getRowResult("select distinct d.disputecode,d.disputename from TB_SS_INSURE_DISPUTE d where 1=1 "+conditon+" order by d.disputecode" );
String dataJSON=null;
if(data != null && data.length > 0){
dataJSON="\"data\":[";
for(int i = 0; i < data.length; i++){
if(i+1==data.length){
dataJSON += "{\"code\":\""+data[i][0]+"\",\"value\":\""+data[i][1]+"\"}";
}else{
dataJSON += "{\"code\":\""+data[i][0]+"\",\"value\":\""+data[i][1]+"\"},";
}
}
dataJSON += "]";
}if(dataJSON != null ){
out.print("{"+dataJSON+"}");
}
public String ajax(String content, String type) {
try {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType(type + ";charset=UTF-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.getWriter().write(content);
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
type:'POST',
contentType:'application/json',
url:'${ctx}/welcome/addUser',
data:jsonuserinfo,
dataType:'json'
});这样就不跳转只传值