Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. $stmt = $mysqli->prepare("SELECT * FROM products LIMIT 10");
  3. $stmt->execute();
  4. $products = $stmt->get_result();
  5. $product_array = array();
  6. while($product = $products->fetch_assoc()){
  7. $product_array[] = $product;
  8. }
  9. echo json_encode($product_array);
  10. ?>
  11.  
  12. <style>
  13. .product
  14. {
  15. width: 100px;
  16. height:100px;
  17. margin-bottom: 10px;
  18. }
  19. </style>
  20.  
  21. <div class="product_area">
  22. <div class="product">
  23. <h3>Product 1</h3>
  24. <p>Price: $10</p>
  25. </div>
  26. <div class="product">
  27. <h3>Product 2</h3>
  28. <p>Price: $10</p>
  29. </div>
  30. <div class="product">
  31. <h3>Product 3</h3>
  32. <p>Price: $10</p>
  33. </div>
  34. <div class="product">
  35. <h3>Product 4</h3>
  36. <p>Price: $10</p>
  37. </div>
  38. </div>
  39.  
  40. $(document).ready(function()
  41. {
  42. $.ajax(
  43. {
  44. url: 'product.php',
  45. dataType: 'JSON',
  46. success: function(data)
  47. {
  48. //This is where I am stucked. How do I append the new data beneath the current data in `product_area`.
  49. for(i=0; i<=data.length; i++)
  50. {
  51. }
  52. window.History.pushState({urlPath:'&view=products'},"",'&view=product');
  53. }
  54. });
  55. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement