您的位置:首页 > 编程语言 > Java开发

Ajax发送同步请求给Spring,通过controller处理完成后如何返回响应

2014-11-09 00:17 645 查看
@RequestMapping("changeState")
public String changeState(HttpServletRequest req){
System.out.println(req.getParameter("status"));
String status = req.getParameter("status");
int id = Integer.parseInt(req.getParameter("id"));
Map<String, Object> map = new HashMap<String, Object>();
if("0".equals(status)){
map.put("status", "1");
map.put("id", id);
costDao.stateChange(map);
}else{
map.put("status", "0");
map.put("id", id);
costDao.stateChange(map);
}
return null;
}

Controller返回值如何填写??

以下是通过Ajax发送的同步请求

function startFee(status, id) {
var r = window.confirm("确定要启用此资费吗?资费启用后将不能修改和删除。");
if(r){
var xhr = getXhr();
xhr.open("get", "changeState.do?status="+status+"&id="+id, false);
xhr.onreadystatechange=function(){
if((xhr.readyState==4)&&(xhr.status==200)){
alert("4");
}
};
xhr.send();
}
document.getElementById("operate_result_info").style.display = "block";
}

解决办法:使用PrintWrite写一个返回值,并且该Controller声明为void
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring ajax
相关文章推荐