`

Jquery的ajax获取action中的返回值msg

    博客分类:
  • ajax
阅读更多
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();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics