Jquery的ajax获取action中的返回值

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();

 

posted on 2014-12-02 11:25  可爱2014  阅读(672)  评论(0编辑  收藏  举报

导航