Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交事件不重定向页面_Javascript_Jquery_Html - Fatal编程技术网

Javascript 提交事件不重定向页面

Javascript 提交事件不重定向页面,javascript,jquery,html,Javascript,Jquery,Html,下面的代码分别显示产品和获取的视图详细信息的图像。单击“查看详细信息”按钮后,它不会重定向到新页面。希望我创建的函数出现问题…请查看我的代码 <?php session_start(); //start session include("config.inc.php"); //include config file ?> <!DOCTYPE HTML> <html> <head> <

下面的代码分别显示产品和获取的视图详细信息的图像。单击“查看详细信息”按钮后,它不会重定向到新页面。希望我创建的函数出现问题…请查看我的代码

   <?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>

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

 $(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();
        });  
});

您应该阅读以下内容:为什么要将所有表单字段放在另一个URL参数中。它可能应该是1stlink.php?+form_数据,为什么要使用重定向来执行此操作?这与使用@Barmar基本相同,你能就我的错误写一个答案吗,希望我在我的演讲中发表不必要的声明code@barmar我在使用表单内的字段时认为,由于url根据单个产品的点击获取动态数据,它会接收单个产品代码,并随url一起传递。为什么他需要将其放在底部?使用$document.ready意味着在加载所有内容之前它不会运行。