2007-03-29

AJAX如何与后台交互

来源: 本站收集整理 作者:佚名 评论 0 条
 
xmlHttp.onreadystatechange = handleReadyStateChange;
xmlHttp.open("post", url, true); //传递数据的方法同样有GET和POST两种,但是当方法为POST时下面的一句话就必须写
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(null);
}
function handleReadyStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
if (xmlHttp.responseText == 'Y') {
document.mainFrm.isExist.value = 'Y';
document.getElementById("flag").style.display = "block"
document.mainFrm.segment10.focus();
} else {
document.mainFrm.isExist.value = 'N';
document.getElementById("flag").style.display = "none"
}
} else {
alert(xmlHttp.status);
}
}
}
后台代码为:
boolean success = itemDAO.doVerifyItem(); //doVerifyItem为验证指定物品是否在数据库中存在的主要方法,假如该物品已存在该方法将返回TRUE
PrintWriter out = res.getWriter();
if (success) {
out.print("Y");
}
out.flush();
out.close();
}
共2页: 上一页 [1] 2 下一页
    评论加载中…

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号