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...