使用AJAX动态刷新购物车?
WP eCommerce 中遇到一个小问题。当我将商品添加到购物车时,我的购物车小部件会立即使用 AJAX 反映更改。但是,如果我的购物车中有商品并且我刷新页面,则我的购物车默认显示“0 件商品”(当我的购物车中实际上仍然有商品时)。然后,当您添加新商品时,将进行 AJAX 调用,并且我的购物车会刷新(添加新商品)。
我的问题是,如何在不实际添加商品的情况下刷新我的购物车?通过调用下面的脚本,我能够向我的购物车添加一个价值为 0 美元的空白商品,但这非常hacky。我只需要发送 AJAX 调用来动态刷新我的购物车,但实际上不需要向其中添加任何内容。有什么想法吗?
<body onload="document.getElementById('refresh-cart').click()">
<form class="product_form">
<input type="hidden" name="wpsc_ajax_action" value="add_to_cart">
<input id="refresh-cart" name="Empty" type="submit">
</form>
</body>
Have a small problem here in WP eCommerce. When I add items to my cart, my cart widget reflects the changes immediately using AJAX. However, if there are items in my cart and I refresh the page, my cart shows "0 items" by default (when there are still actually items in my cart). Then when you add a new item, the AJAX call is made, and my cart refreshes (adding the new item).
My question is, how do I refresh my cart without actually adding an item? By calling the script below, I was able to add a blank item to my cart with a value of $0, but this is pretty hacky. I just need to send an AJAX call to refresh my cart dynamically, but not actually add anything to it. Any ideas?
<body onload="document.getElementById('refresh-cart').click()">
<form class="product_form">
<input type="hidden" name="wpsc_ajax_action" value="add_to_cart">
<input id="refresh-cart" name="Empty" type="submit">
</form>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在一定的时间间隔调用 ajax 函数来刷新购物车:
希望有帮助
You could call your ajax function at certain intervals fr refreshing cart:
Hope it helps
首先,您尝试做的事情不是有效的电子商务方法,这可能会导致许多其他问题。
您所说的是,我相信是迷你购物车,并且在页面刷新时,如果其显示的总量为零,则您的代码或迷你购物篮的实现存在问题。
mu的建议是调试导致此问题的问题,而不是胡思乱想:)
The first thing is place is what you trying to do is not a valid e-commerce approach and this can lead to many other issues.
what you are talking about is i believe is mini-cart and on page refresh if its showing total quantity as zero than either there is some problem in your code or in the implementation of mini-basket.
mu suggestion would be to debug the issue which is causing this problem rather than going for a heck :)