0

I have a shop which uses dynamic content. Users can click on checkboxes to view products of specific categories. For this I am using jQuery to get products from another php file (works fine).

shop.php:

<input type="checkbox" class="category_btn" name="cat" id="category-books" value="books"> <input type="checkbox" class="category_btn" name="cat" id="category-dvds" value="dvds"> ... <div id="allProducts"> Load dynamic content with jQuery here... </div> 

loadProducts.php:

<?php $categories = $_POST['categories']; $productsData = load_products($categories); for ($i = 0; $i < $amount; $i++) {?> <div class="singleproduct"> <a href="product.php?id=<?php echo $productsData[$i]['ID'] ?>"><img src="images/<?php echo get_image($productsData[$i]['ID']) ?>" alt=""></a> <p class="prod-title"><?php echo $productsData[$i]['title'] ?></p> </div> <?php }?> 

jQuery code (shop.php):

<script> jQuery(document).ready(function($) { var checkedCats = []; $(".category_btn:checked").each(function() { checkedCats.push($(this).val()); }); $(".category_btn").click(function () { var arraydata = {"categories[]" : checkedCats}; $.post('loadProducts.php', arraydata, function (data) { var test = $('#allProducts').html(data); }); }); }; </script> 

Now if a user clicks on a product to view details and then returns to shop.php by using the back-button, he will see the main page of the shop with no dynamic loaded content. Is it possible to save the last view with marked checkboxes and loaded products? I think history.js is the solution, but I have no idea how to do this. Maybe somebody can help...

6
  • It's a dup of stackoverflow.com/questions/9046184/… go there. Commented Oct 20, 2017 at 16:48
  • It is not. I am not adding any gets to the url so reloading the page does nothing. Commented Oct 20, 2017 at 16:55
  • When the back button is pushed, the website goes to it's original state. The URL I linked mentions how to force a reload so that you can see your items. I don't know if history.js can solve your problem, I looked at it and didn't see that Commented Oct 20, 2017 at 17:19
  • Mhm maybe it doesn't, I'm not sure. But a reload does not check the checkboxes, so I only see the main page of the shop with no category limitations. Commented Oct 20, 2017 at 17:23
  • Oh, that's a much harder item as you would have to ajax the setttings somewhere and then the reload would pull them back. Using Back Button with AJAX settings causes lots of issues Commented Oct 20, 2017 at 18:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.