var xmlreq = false;functioncreateXmlHttpRequest()
{if(window.XMLHttpRequest) {
xmlreq= newXMLHttpRequest();
}else if(window.ActiveXObject) {try{
xmlreq= new ActiveXObject("Msxml2.XMLHTTP");
}catch(e1) {try{
xmlreq= new ActiveXObject("Microsoft.XMLHTTP");
}catch(e2) {
}
}
}returnxmlreq;
}functiondel(id){var request =createXmlHttpRequest();
request.open("post","/StuServlet?methodName=delete&id="+id);
request.send();
request.onreadystatechange=function(){if (xmlreq.readyState == 4)
{if (xmlreq.status == 200)
{var check =xmlreq.responseText;
show (check);
刪除public int delete(int i){
Connection conn = new ConnectionUtil().openConnection();
try{
PreparedStatement ps = conn.prepareStatement(DELETE_STUDENT_SQL);
ps.setInt(1,i);
ps.executeUpdate();
return 1;
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
return 0;
}
private void delete(HttpServletRequest request, HttpServletResponse response)
throws IOException {
// TODO Auto-generated method stub
int id =Integer.parseInt(request.getParameter("id"));
StudentDao dao =new StudentDaoImpl();
PrintWriter out = response.getWriter();
if(dao.delete(id)==1){
out.write("OK");
}
else{
out.write("NO");
}
//query(request, response);
out.close();
}
自己硬着头皮做的一个ajax的删除异步刷新
原文:http://www.cnblogs.com/yanz/p/3866102.html