使用jquery异步无刷新删除
实现截图:
jquery异步无刷新删除各方面的代码:
html:
<a href="javascript:delGoods(<s:property value="Auto_No"/>)">删除</a>
jquery:
//删除对应goodsID的商品
function delGoods(goodsID) {
if(confirm( "确定要删除?" ))
{
$.get("/BackManage/manage/goodsManage_deleteGoods?goodsID=" +goodsID,null,function(data){
$("#"+goodsID).remove();
$("#result").html("删除成功");
});
}
}
当然要在html中引入jquery库
Action:
/**
* 删除商品
* @return
*/
public void deleteGoods(){
boolean ok=goodsCodeService.delete(goodsID);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
try {
PrintWriter pw = response.getWriter();
if(ok==true){
pw.write(1);
}else{
pw.write(0);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}