php删除按钮不断检索发布的信息
我有一个很快的问题,我有一个购物车的删除按钮,除了购物车中的最后一个产品之外,代码每次都适用。如果用户按下 addtoCart 按钮,URL 将重新加载 ?buyproduct=$productNumber
,并且当按下删除按钮时,产品将被删除。是的,所以一切都很好,但是当您尝试删除最后一项时,它会继续读取 URL 中的产品。因此当前 $productNumber
的数量仍为 1。
我尝试在表单方法标记中添加操作,以便页面在没有 ?buyproduct=$productNumber
的情况下重新加载,这确实有效,但是 URL 中也有页码和部分,这些也重置。
我知道删除正在起作用,因为一旦 ?buyproduct=$productNumber
从 URL 中消失(例如,如果它们转到目录中的另一个部分,就会发生这种情况),然后购物车就可以完全清空。
I have a quick problem, I have a remove button for a shopping cart and the code works for it everytime except for the last product thats in the cart. If a person pushes the addtoCart button the URL is reloaded with ?buyproduct=$productNumber
and when the remove button is pushed the product is removed. Right so everything is good, but when you try to remove the last item, it keeps reading the product thats in the URL. so the quantity remains 1 for the current $productNumber
.
I've tried adding the action in the form method tag so that the page reloads without the ?buyproduct=$productNumber
, which does work however there are page numbers and sections that were also in the URL and these get reset also.
I know the remove is working because once the ?buyproduct=$productNumber
is gone from the URL (which can happen for example if they go to another section in the catalog) then the cart can be completely emptied.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好调查一下现有的操作,而不是更改 表单操作做。看起来这就像设置或取消设置某些 GET 变量一样简单。
您可以从表单操作中指定的脚本中发布一些代码吗?
Instead of changing the form action, it seems prudent for you to investigate what the existing action does. It seems as if this could be as simple as setting or unsetting some GET variable.
Can you post some code from the script named in your form's action?
显然,您的产品删除表单提交被您的 FORM 操作也试图将产品重新添加到您的购物车这一事实所抵消。也许最简单的解决方案是向 FORM 操作添加一个开关,例如
?remove=1
,然后您可以在处理buyproduct
的情况之前检查该开关,完全跳过该部分。但请注意,这不是最干净的解决方案,因为您将不必要的 GET 变量发送到服务器(主要是
buyproduct
)。解决此问题的方法可能是您只需为表单操作重新生成查询字符串:然后您需要使用
$str
作为您的 FORM 操作:Clearly your product removal form submission is being offset by the fact your FORM action is also trying to re-add the product to your cart. Perhaps your easiest solution would be to add a switch to your FORM action like
?remove=1
which you can then check for before handling the case ofbuyproduct
, skipping that section entirely.Note that this is not the cleanest solution, however, because you have uneccessary GET variables being sent to the server (mainly
buyproduct
). A workaround for this could be for you to simply regenerate the query string for your form action:You would then want to use
$str
as your FORM action: