JS文件中的函数:
function delinvest(ids) {
var id=ids;
$.ajax({
type : "post",
url : "/servletinout?do=del&id="+id+"",
cache : true,
async : true,
success: function (msg ){
if(msg=='1'){
alert('成功了');
queryinvest();
}
//alert('2');
if(data.code == 200){
alert("插入成功了");
}else{
alert(data.message);
}
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(typeof(errorThrown));
}
});
}
Servlet中的方法:
if(dos.equals("del")){
String ids=request.getParameter("id");
int id=Integer.parseInt(ids);
int num=inoutDao.del(id);
if(num==1) {
/*out.print("<script>alert('删除成功!');"
+ "window.location='servletinvestment?do=queryall';</script>");*/
//out.print("<script>alert('删除成功!');</script>");
out.print("1");
//return ;
}
}
接口类新增的方法:
public int del(int id);
实现类中方法:
public int del(int id){
int num=0;
String sql = "delete from tb_inout where id=?";
try {
num = executeUpdate(sql, id);
}
catch (Exception e) {
e.printStackTrace();
}
return num;
}