ajax请求后台并接收返回数据 前台页面jQuery.ajax({method:"post",url:"%=path %/lrCbSyYz.action?timestamp=" + new Date().getTime(),async:false,dataType:"json",data:{year:year,ptname:ptname}, success: function(res){ if(res[0].resu
前台页面
jQuery.ajax({
method:"post",
url:"<%=path %>/lrCbSyYz.action?timestamp=" + new Date().getTime(),
async:false,
dataType:"json",
data:{year:year,ptname:ptname},
success: function(res){
if(res[0].result==0){
alert("------");
}
},error: function(){ //失败
alert("-----");
}
});
后台存值返回
public void lrCbSyYz(){
......
JsArray jsArray=new JsArray();
Json json = new Json();
json.put("result", "1");
jsArray.add(json);
response.setCharacterEncoding("utf-8");
try {
response.getWriter().print(jsArray.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
