首页 > 代码库 > jsp servlet ajax入门删除
jsp servlet ajax入门删除
<script type="text/javascript">var xmlreq = false; function createXmlHttpRequest(){ if (window.XMLHttpRequest) { xmlreq = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { try { xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { } } } return xmlreq;}function del(id){ var request = createXmlHttpRequest(); request.open("post","<%=path%>/StuServlet?methodName=delete&id="+id); request.send(); request.onreadystatechange=function(){ if (xmlreq.readyState == 4) { if (xmlreq.status == 200) { var check = xmlreq.responseText; show (check);
<TD><a href="javascript:void(0)" onclick="del(<%=id%>)">刪除</a></TD>
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的删除异步刷新
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。