ajax 与后台交互后返回相应的字符串

来源:互联网 发布:开启式电机铭牌数据 编辑:程序博客网 时间:2024/04/26 09:35

前台

$.ajax({

  type: "post",

  url: "<c:url value='/office/word!getPostReportInfo.do' />",

  data: {items: selectedItems.join(',')},

  async:false,

  success: function(date){

    if(date==0){

alert("选中的数据中存在已经上报的数据");

    }

  }

});

 

后台

public void getPostReportInfo() throws Exception{

outTxt("0");

}

public void outTxt(String str) {

try {

getResponse().setContentType("text/html;charset=UTF-8");

PrintWriter out = getResponse().getWriter();

out.println(str);

out.flush();

out.close();

} catch (IOException e) {

e.printStackTrace();

}

}

此段代码执行后,前台alert成功!

原创粉丝点击