Struts2和Jquery整合使用异步请求

Action 中要调用的方法:   

/**
* 查询检测记录(异步请求)
* @return
*/
public void find(){
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest ();    
response.setContentType("text/xml");
response.setCharacterEncoding("GB2312");
PrintWriter writer = null;
//分页信息
PageBean page = new PageBean();
page = PageHandler.initPage();
if (index != null) {
page.setGotoPage(index);
} 
try {
request.setCharacterEncoding("iso-8859-1");
writer = response.getWriter();
view = recordService.findRecordByCondition(recordForm, page);//调用底层接口返回数据
StringBuffer buffer = ActionBean.getRecordQueryString(view, request);//进行数据封装(html)
writer.write(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
}finally{
if (writer != null)
writer.close();
}

response.setHeader("Charset", "GB2312");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
}

 

配置文件:
<!-- 查询历史检测记录 -->    
<action name="find" class="com.sclead.web.action.record.RecordAction" method="find"/>

页面JS函数:
//查询历史记录

function queryRecord(index){
var form = document.getElementById("find");
form.x_index.value=index;//页码
//参数
var parameter = "depId="+form.depId.value+"&devId="+form.devId.value+
"&locoType="+form.locoType.value+"&locoNO="+form.locoNO.value+
"&panType="+form.panType.value+"&isLoad="+form.isLoad.value+
"&startTime="+form.startTime.value+"&endTime="+form.endTime.value+
"&index="+index+"&flag=2";
$.ajax({
type:"GET",
url:"<%=path%>/record/find",
dataType: 'html',
cache:false,
data:parameter,
success:function(text){
//执行成功以后动态替换也页面内容,因为返回的格式为Html,直接显示即可
document.getElementById("content").innerHTML = text;    
}
});
}
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值