js部分:
function check() {
$.ajax({
type : "POST",
url : "myCloudWantseeListHD.action",
data : "type=2&kind=1&id=1",
async:false,
cache:false,
success : function(msg) {
alert(msg);
},
error : function(e) {
alert("error");
}
});
}
注意:
async是asynchronous[异步]的缩写,它是一个bool值默认为true。当async为true时,先不管ajax请求是否完成都要向下执行。同步请求要临时锁定浏览器,当请求正在执行时不执行任何动作。
action中的java关键code:
String msg = "fa";
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.print(msg);
out.flush();
out.close();