SpringMvc 使用ajax返回JavaScript

来源:互联网 发布:淘宝店卖家信誉等级表 编辑:程序博客网 时间:2024/06/05 02:00

java程序:

/** * 删除 */@RequestMapping(value = "/deleteBest", method = RequestMethod.POST ,produces = "application/json; charset=utf-8")public @ResponseBodyString deleteBest(Long id,Long bestid) {String error = "参数错误!";  if(id == null || bestid == null){   return "$.message(\"" + Message.Type.success + "\", \"" + error + "\");";}else{Product product = productService.find(id);if(product != null){Set<Product> bests = product.getBestGroup();Iterator<Product> iter = bests.iterator();while(iter.hasNext()){Product p = iter.next();if(p.getId() == bestid){iter.remove();}}product.setBestGroup(bests);productService.update(product);String success = "删除成功!";return "$.message(\"" + Message.Type.success + "\", \"" + success + "\");";}}     return "$.message(\"" + Message.Type.success + "\", \"" + error + "\");";}

前台程序:
//删除一个最佳组合function deleteBest(id,bestid){$.ajax({url:"deleteBest.jhtml",type:"post",data:{id:id,bestid:bestid},dataType:"script",success:function(msg){//执行脚本并删除节点eval(msg);$("#li"+bestid).remove();var index = array.indexOf(id);array.remove(index);}});}



0 0
原创粉丝点击