weixin_33725515 2016-11-03 18:11 采纳率: 0%
浏览 24

查看产品按钮

I have trawled the internet over the past few hours to find out the best way to add a view product button to my website. I have seen it done via a Bootstrap Modal but i don't want a modal, i want the product to display on a fresh page (Products.php).

i have created a button to view the products, and started to code an Ajax call

function productdetails(id){
var data = {"id":id};
jQuery.ajax({
  url : 'products.php',
  method : "post",
  data : data,
  success : function(data){
    jQuery('body').append(data);

  },
  error : function(){
    alert("Something went wrong!");
  }
});
}

but i know with a modal you need to add:

  JQuery('#modalname').modal ('toggle')

Anybody got any suggestions, as it seems all websites are using this method of a new page for product details rather than a modal.

  • 写回答

1条回答 默认 最新

  • weixin_33725126 2016-11-03 19:02
    关注

    This is sent to the page with the code you want to display lets just call it product.php for example.

    function productdetails(id){
        var data = {"id":id};
        jQuery.ajax({
          url : 'products.php',
          method : "post",
          data : data,
          success : function(data){
            jQuery('body').append(data);
    
          },
          error : function(){
            alert("Something went wrong!");
          }
        });
        }
    

    product.php might look something like this

    <?php
    $id = $_POST['id'];
    $results = mysql_query('get information');
    ?>
    
    <html>
       <examplenode>
           <?php echo $results['product_title']; ?>
       </examplenode>
    </html>
    

    ^ Above is what the js will get when the request is sent, then just replace the the current html

    $('body').replace(data);
    
    评论

报告相同问题?