提交事件不重定向页面

时间:2017-05-05 22:08:20

标签: javascript jquery html

以下代码与产品一起显示图像并分别获取视图详细信息。一旦查看详情'单击按钮不会重定向到新页面。希望我的功能创建问题....请查看我的代码

   <?php
    session_start(); //start session
    include("config.inc.php"); //include config file
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Ajax Shopping Cart</title>
    <link href="style/style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
    <script>
    $(document).ready(function(){   
            $(".form-item").submit(function(e){
                var form_data = $(this).serialize();
                var button_content = $(this).find('button[type=submit]');
                window.location = "1stlink.php?variable=" + encodeURIComponent(form_data);
                //button_content.html('Adding...'); //Loading button text
                 e.preventDefault();
            });  
    });
    </script>
    </head>
    <body>
    <div align="center">
    <h3>Product list view</h3>
    </div>
    <?php
    //List products from database
    $results = $mysqli_conn->query("SELECT product_name, product_desc, product_code, product_image, product_price FROM products_list");
    //Display records from database
    $products_list =  '<ul class="products-wrp">';

    while($row = $results->fetch_assoc()) {
    $products_list .= <<<EOT
    <li>
    <form class="form-item">
    <h4>{$row["product_name"]}</h4>
    <div><img src="images/{$row["product_image"]}"></div>
    <div>Price : {$currency} {$row["product_price"]}<div>
    <div class="item-box">     
        <input name="product_code" type="hidden" value="{$row["product_code"]}">
        <button type="submit">View details</button>
    </div>
    </form>
    </li>
    EOT;

    }
    $products_list .= '</ul></div>';

    echo $products_list;
    ?>
    </body>
    </html>

1 个答案:

答案 0 :(得分:-1)

将此脚本作为最后一个元素放在正文的底部。

.