购物车列表删除一项后,页面不刷新。

Dmllm 2015-09-25 10:46:45
购物车列表删除一项后,页面不刷新,在ie下好用,chrome和firefox失效。,应该怎么刷新这个购物车列表的窗口呢。删除的click事件如下:
deleteItem:function(itemid){
var self=this;
$.Loading.show("请稍候...");
$.ajax({
url:"api/shop/cart!delete.do?ajax=yes",
data:"cartid="+itemid,
dataType:"json",
success:function(result){
$.Loading.hide();
if(result.result==1){
self.loadNum();
self.barWrapper.find(".item[itemid="+itemid+"]").remove();
//如果是在购物车页面更新购物车相应信息
if(typeof Cart != "undefined"){
Cart.removeItem(itemid);
Cart.refreshTotal();
}
}else{
$.alert(result.message);
}
},
error:function(){
$.Loading.hide();
$.alert("出错了:(");
}
});
},
...全文
724 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35552988 2016-11-28
  • 打赏
  • 举报
回复
请问楼主这个问题解决了吗 我也遇到了同样的问题
Dmllm 2015-09-25
  • 打赏
  • 举报
回复
<#assign cartTag= newTag("cartTag")> <#assign itemList = cartTag() > <style> .my_cartlist_all{overflow:hidden;position:relative;} </style> <#if (itemList?size>0) > <div class="my_cartlist_all"> <#list itemList as item> <dl itemid="${item.id}" class="item"> <dd class="goods_thumb"> <span class="thumb size40" > <a target="_blank" href="${ctx}/goods-${item.goods_id}.html" title="${item.name}" > <@image height="40" width="40" src="${item.image_default!''}" style="cursor: pointer;" /> </a> </span> </dd> <dt class="goods_name"> <a href="${ctx}/goods-${item.goods_id}.html">${item.name} <#if item.others.specList?exists> <span> <#list item.others.specList as spec> <#if spec_index!=0></#if><strong>${spec.name}:<em style="color:#ED7108">${spec.value}</em></strong> </#list> </span> </#if> </a> </dt> <dd class="goods_price"><p>¥${item.price}×${item.num}</p></dd> <dd class="handle"> <a href="javascript:void(0)" itemid="${item.id}" class="delete">删除</a> </dd> </dl> <!-- 暂时无内容,先取消 <#if item_has_next> </#if> --> </#list> </div> <div class="checkout"> <a class="btn-cart" href="${ctx}/cart.html">查看我的购物车</a> </div> <#else> <p style="border:0px!important;" class="no_cartlist">您的购物车中还没有任何商品</p> </#if> <script> $(function(){ if($(".my_cartlist_all dl").length > 2){ $(".my_cartlist_all").jscroll(); $(".my_cartlist_all").css("height","200px"); } }) </script> 上面是页面。下面是js。 /** * 购物车Bar * @author kingapex * 提供购物车Bar数量加载及悬停效果 * 并暴露加载数量接口供其它程序使用 */ var CartBar={ /** * 初始化方法 * 1.加载数量 * 2.绑定hover事件 */ init:function(){ var self = this; this.barWrapper = $(".my_cart"); //购物车bar主元素 this.numBox = this.barWrapper.find(".addcart_num"); //数量元素 var contentBox = this.barWrapper.find(".content"); //购物列表元素 var listBox = this.barWrapper.find(".my_cartlist"); //购物列表元素 this.loadNum(); this.barWrapper.hover( function(){ $(this).addClass("hover"); // contentBox.show(); //显示loading 图标 $.ajaxSetup ({ cache: false }); //jquery ajax 的load()方法IE下无法获取页面内容 listBox.load(ctx+"/cart/cart_bar.html",function(){ //加载完列表绑定删除事件 $(this).find(".delete").click(function(){ var itemid = $(this).attr("itemid"); self.deleteItem(itemid); }); }); },function(){ $(this).removeClass("hover"); contentBox.hide(); } ); }, /** * 购物车项删除 * @param itemid */ deleteItem:function(itemid){ var self=this; $.Loading.show("请稍候..."); $.ajax({ url:"api/shop/cart!delete.do?ajax=yes", data:"cartid="+itemid, dataType:"json", success:function(result){ $.Loading.hide(); if(result.result==1){ self.loadNum(); self.barWrapper.find(".item[itemid="+itemid+"]").remove(); //如果是在购物车页面更新购物车相应信息 if(typeof Cart != "undefined"){ Cart.removeItem(itemid); Cart.refreshTotal(); } }else{ $.alert(result.message); } }, error:function(){ $.Loading.hide(); $.alert("出错了:("); } }); }, /** * 加载购物车中的商品数量 * */ loadNum:function(){ var self = this; $.ajax({ url: ctx+"/api/shop/cart!getCartData.do?ajax=yes", dataType:'json', cache:false, success:function(result){ if(result.result==1){ $(".addcart_num").text(result.data.count); $.ajax({ url:ctx+"/cart/cartTotal.html", dataType:"html", success:function(html){ $(".total_wrapper").html(html); }, error:function(){ alert("糟糕,出错了:("); } }); } } }); } };
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
你不要用find。你id不是传进去了吗?直接jquery取到 然后移除,用类似于这种方法$("#"+id).remove();
Dmllm 2015-09-25
  • 打赏
  • 举报
回复
不行的。那句只是删了列表里显示的。删除完其他的商品的删除还是失效了
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
...怎么会不行,我说你的delete方法里面只留移除item的方法看下。这样都不行?
Dmllm 2015-09-25
  • 打赏
  • 举报
回复
还是不行啊,是不是哪个方法chrom浏览器下无效啊
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
self.barWrapper.find(".item[itemid="+itemid+"]").remove(); 这个代码是移除商品的js吧,删除的时候只留这个看下
Dmllm 2015-09-25
  • 打赏
  • 举报
回复
不报错,ie下就有效。chrome和firefox下不行。
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
js报错,用调试工具看下哪一行报错了,查下问题
Dmllm 2015-09-25
  • 打赏
  • 举报
回复
不是,是删除一个之后,其他的再点删除就没有用了。必须鼠标移出再重新获得购物车列表才能再删除
qq_14924735 2015-09-25
  • 打赏
  • 举报
回复
为什么一定要刷新呢? 除掉不就好了? 其实刷新是在给服务器承担压力!
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
购物车页面为啥要刷新,你移除掉就可以了
超级菜鸟 2015-09-25
  • 打赏
  • 举报
回复
你这代码js里面的init方法 this.barWrapper = $(".my_cart"); //购物车bar主元素 this.numBox = this.barWrapper.find(".addcart_num"); //数量元素 var contentBox = this.barWrapper.find(".content"); //购物列表元素 var listBox = this.barWrapper.find(".my_cartlist"); //购物列表元素 这几个元素都有吗?为什么我在页面上找不到?

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧