Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. $(function() {
  2.  
  3. $.get( '/api/products/list' , function( data ){
  4. }).done(function( data ) {
  5. // TO DO ON DONE
  6. //console.log("data: ", data);
  7. //console.log("Success");
  8. showProducts(data);
  9. }).fail(function(data, textStatus, xhr) {
  10. //This shows status code eg. 403
  11. //console.log("error", data.status);
  12. //This shows status message eg. Forbidden
  13. //console.log("STATUS: "+xhr);
  14. }).always(function() {
  15. //TO-DO after fail/done request.
  16. //console.log("ended");
  17. });
  18. // Initialize form validation on the registration form.
  19. // It has the name attribute "registration"
  20. $("#frmLogin").validate({
  21. // Specify validation rules
  22. rules: {
  23. // The key name on the left side is the name attribute
  24. // of an input field. Validation rules are defined
  25. // on the right side
  26. userName: "required",
  27. password: {
  28. required: true,
  29. //minlength: 8
  30. }
  31. },
  32. // Specify validation error messages
  33. messages: {
  34. userName: "Please enter your user name",
  35. password: {
  36. required: "Please provide a password",
  37. //minlength: "Your password must be at least 8 characters long"
  38. }
  39. },
  40. // Make sure the form is submitted to the destination defined
  41. // in the "action" attribute of the form when valid
  42. submitHandler: function(form) {
  43.  
  44. }
  45. });
  46. });
  47.  
  48.  
  49. function showProducts(data) {
  50. var htmlShopProducts = "";
  51. var htmlShopProduct = "";
  52. var htmlImg = "";
  53. $("#lblShopList").html("");
  54. for (var i = 0; i < data.length; i++) {
  55. if( data[i].Product_PictureURL == "test" || data[i].Product_PictureURL == ""){
  56. htmlImg = '<img src="/images/1000.png" class="img-fluid img-thumbnail" alt="product">'
  57. } else {
  58. htmlImg = '<img src="' +data[i].Product_PictureURL +'" class="img-fluid img-thumbnail" alt="product">';
  59. }
  60.  
  61. htmlShopProduct = '<div class="col-3 single-product">\
  62. <a href="#">\
  63. ' + htmlImg+'\
  64. <span class="caption simple-caption">\
  65. <span class="name">'+data[i].Product_Name+'</span>\
  66. <span class="price">₤'+data[i].Product_Price+'</span>\
  67. <button class="btnViewProduct btn btn-gold my-2 my-sm-0 text-uppercase" data-id="'+ data[i].Product_UID +'">View</button>\
  68. </span>\
  69. </a>\
  70. </div>';
  71.  
  72. htmlShopProducts += htmlShopProduct;
  73.  
  74. }
  75. $("#lblShopList").html(htmlShopProducts);
  76. accessSingleProduct();
  77. }
  78.  
  79. checkSession();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement