function ajaxSave(URLS) {
//定義一個(gè)變量用于存放XMLHttpRequest對(duì)象
var xmlhttp;
//定義一個(gè)變量用于存放 從服務(wù)器返回的響應(yīng)結(jié)果
var responseContext = "";
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {responseContext = xmlhttp.responseText;
alert(responseContext);
}
}xmlhttp.open("POST", URLS, true);
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send();
}
后臺(tái)方法:
代碼如下:
Boolean boolean1;
String reponseText = "";
if(boolean1){
reponseText="保存成功!";
}
else{
reponseText="保存失敗!";
}
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.println(reponseText);
out.flush();
out.close();
return null;
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com