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();
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();
本文介绍了一个使用jQuery实现的JavaScript同步Ajax请求示例。该示例通过POST方式向服务器发送请求,并展示了如何处理响应消息及错误情况。此外,还提供了服务器端Java代码示例,用于设置响应内容。

875

被折叠的 条评论
为什么被折叠?



