在 Magento 中对一长串复选框进行分页
如果有人能帮助我解决这个问题那就太好了 - 我已经花了一天多的时间了。 :(
在 Magento 的 phtml 文件中,我显示一长串产品列表,每个产品旁边都有一个复选框。我已经添加了一些代码来对该列表进行分页。问题是,当我转到第 2 页时,我需要“记住”在第 1 页中选择了哪些框,并在返回到第 1 页时选择它们。我知道如何使用 javascript 来检测复选框是否被选中,我打算保存一组选定的框。在 magento 会话中 - 当选中更多框时添加它,并在取消选中框时删除它,但我的会话更改代码是 PHP,而我的复选框检测器是 javascript。 javascript - 我被告知我需要 AJAX 来做到这一点,我根本不知道任何 AJAX 可以做到这一点,
如果有人可以的话,我很乐意发布我的代码的相关片段。帮助我。谢谢
! 好吧,所以我最终还是决定使用 AJAX,而且我已经添加了很多 AJAX 代码。问题是,它不起作用。顺便说一句,我没有使用 jQuery。当我在 Magento 中编写此内容时:
xmlhttp.open("POST", 'adjust_session.php', true); xmlhttp.send(参数);
我到底需要将 adjustment_session.php 文件放在哪里?如果我将它放在与我的 phtml 文件相同的文件夹中(我在其中调用 open 函数),它就不起作用。
谢谢!
it would be awesome if someone could help me with this - I've already spent more than a day on it. :(
In a phtml file in Magento, I'm displaying a long list of products with a checkbox next to each. I've already added some code to paginate this list. The problem is, when I move to say page 2, I need to 'remember' which boxes were selected in page 1, and select them when I move back to page 1. I know how to use javascript to detect if a checkbox is checked or not. I was planning to save an array of selected boxes in the magento session - adding to it when more boxes are checked and deleting when boxes are unchecked. But my session-changing code is PHP, and my checkbox-detector is javascript. I know I can't call my session-changing function from javascript - I've been told that I would need AJAX to do this. I don't know any AJAX at all. Is there any other way to do this?
I'd be happy to post relevant snippets of my code if anyone can help me. Thanks!
UPDATE:
Okay, so I decided to use AJAX after all, and I've added a lot of AJAX code already. The problem is, it's not working. Btw, I'm not using jQuery. When I write this in Magento:
xmlhttp.open("POST", 'adjust_session.php', true); xmlhttp.send(params);
exactly where do I need to put my adjust_session.php file? It's not working if I put it in the same folder as my phtml file (where I'm calling the open function).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上是如何进行分页的?如果您无论如何都必须往返服务器以获取分页数据,请发送一个已选中/未选中的列表,并在会话中进行切换。然后,在渲染新页面时,要么直接选中 HTML 中的框,要么只是将当前选中框的列表作为 JS 传递并在响应中解析它。
或者,如果您在一个页面上完成所有操作(并且已经使用 AJAX 进行分页),您也可以保留 JS 中的一个数组,并在渲染后重新检查这些框。
希望有帮助!
谢谢,
乔
How are you actually doing the pagination? If you have to make a round-trip to the server for the paginated data anyway, send a list of checked/unchecked with it and toggle in the session. Then, when rendering the new page, either check the boxes in the HTML directly, or just pass a list of currently checked boxes in as JS and parse it on the response.
Alternatively, if you are doing everything on one page (and using AJAX for pagination already), you could also hold onto an array in JS and recheck the boxes after you render them.
Hope that helps!
Thanks,
Joe