怎么查看ajax后台返回的数据

2025-04-12 13:37:28
推荐回答(2个)
回答1:

success: function (data) {
alert(JSON.stringify(data));

}

回答2:

如jsp中代码:
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
alert(xmlhttp.responseText);//此处获取返回数据
}
}
xmlhttp.open("GET","service/toupdstatus.htm“,true);
xmlhttp.send();
后台:HttpServletResponse res=ServletActionContext.getResponse();
res.setCharacterEncoding("utf-8");
try {
res.getWriter().write("Has been successfully changed!");
} catch (Exception e) {
e.printStackTrace();
}
到此ok,方法返回类型为void,struts.xml内不用写标签