$(document).ready(function(){
  submitSearch();
}); 

var submitSearch = function(){
  $("#product-search").on('submit', function(event){
    event.preventDefault();

   var request = $.ajax({
    url:"http://localhost:3000/products/results",
    data: $(this).serialize(), 
    crossDomain: true,
    type:"GET"
   });

   request.done(function(data){
    console.log(data);
    console.log("successssssss");
    $("#product-search").hide();
    $(".search-results").prepend(data);
   });
   request.fail(function(data){
    console.log("fail");
   });
  });
};


$(document).ready(function(){
  hardLanding();
  submitSearch()
}); 



var hardLanding = function(){
  $('a').on('click', function(event){
    event.preventDefault();

  $('a').remove();
  $(".search-product-form").css("display", "block");
  });
};


var submitSearch = function(){
  $("#product-search").on('submit', function(event){
    event.preventDefault();

   var request = $.ajax({
    url:"http://localhost:3000/products/results",
    data: $(this).serialize(), 
    crossDomain: true,
    type:"GET"
   });

   request.done(function(data){
    debugger
    console.log("successssssss");

    var products = data["products"]


    for(i = 0; i < products.length; i++){
      $(".search-results").prepend("<div class='product'><a href='" + products[i].clickUrl + "'>" + "<img src='" + products[i].image.sizes.IPhoneSmall.url + "' alt='product Image'>" + "</a></div>")
    };

   });

   request.fail(function(data){
    console.log("fail");
   });
  });
};


modify js file for the api to display newest items