ajax 與後臺互動後返回相應的字串
阿新 • • 發佈:2019-02-02
前臺
$.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成功!