【问题标题】:form submit doesn't work in php表单提交在php中不起作用
【发布时间】:2015-10-22 18:41:19
【问题描述】:

该文件是选中复选框时使用ajax对表格进行排序的返回文件,
但是提交按钮在以下编码中不起作用,
据我所知,这段代码什么时候似乎没有问题

    <!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("form").submit(function(){
        alert("Submitted");
    });
});
</script>
</head>
<body>

<table>
    <tr>
        <th class="heading"> 
        Sl No.
        </th>
        <th class="heading"> 
        Order Id
        </th>
        <th class="heading"> 
        Date
        </th>
        <th class="heading"> 
        Process
        </th>
        <th class="heading"> 
        Curr Status
        </th>
        <th class="heading_blank"> 
        Change Status
        </th>
        <th class="heading_blank"> 

        </th>
    </tr>

    <?php
    include "config.php";
    $checkbox = isset($_POST['checked_box']);
    if($checkbox == 1){
        $Query="SELECT * FROM `order` ORDER BY sl_no DESC";
    }else{
        $Query="SELECT * FROM `order` ORDER BY sl_no ASC";    
    }
    $result=mysql_query($Query);
    while($row = mysql_fetch_object($result)) { 
    ?>

    <tr>
        <td class="content"> 
        <?php echo $row->sl_no; ?>
        </td>
        <td class="content"> 
        <?php echo $row->order_id; ?>
        </td>
        <td class="content"> 
        <?php echo $row->pick_date; ?>
        </td>
        <td class="content"> 
        <?php echo $row->process; ?>
        </td>
        <td class="content"> 
        <?php echo $row->status; ?>
        </td>
        <form action="update_status.php?order_id=<?php echo $row->order_id; ?>" method="POST">
                <td>
                <div class="select-style">              
                <select name="status">
                    <option value="<?php echo $row->status; ?>"><?php echo $row->status; ?></option>
                    <option value="Step_1">Step_1</option>
                    <option value="Step_2">Step_2</option>
                    <option value="Step_3">Step_3</option>
                    <option value="Step_4">Step_4</option>
                </select>
                </div>
                </td>
                <td> 
                <input type="submit" class="order_details_btn" value="Change">
                </td>
                </form>
        </tr>
    <?php } ?>
    </table>
    </body>
</html>

这个页面来自这个文件

<!doctype html>
<html lang="en">
    <head>
        <title></title>
        <link rel="stylesheet" href="style.css">
        <script src="script.js"></script><script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script type="text/javascript">
            function getOrderStatus(value) {
                $.post("getOrderStatus.php", {partialOrderStatus:value},function(data){
                    $("#results").html(data);
                }
                ); 
            }
        </script>

        <script type="text/javascript">
            function sortOrder() { 
            $.ajax( {
                type: 'POST',
                url: 'sortOrder.php',
                data: { checked_box : $('input:checkbox:checked').val()},

                success: function(data) {
                    $('#results').html(data);
                }
            } );
            }
            </script>
    </head>
    <body>


    <div id="floating-menu">

    <div id="order_tab">
                <div class="form_bg_alpha_order_status">

        <table id="order_hist">
        <tr>
            <td style="width:120px;">Search by:<input type="checkbox" name="checked_box" value="1" onclick="sortOrder()"></td>
            <td style="width:840px;"><input class="search" type="text" onkeyup="getOrderStatus(this.value)" placeholder="Order Id"/></td>
            </tr>
        </table>
        <div id="results">
        <table>
            <tr>
                <th class="heading"> 
                Sl No.
                </th>
                <th class="heading"> 
                Order Id
                </th>
                <th class="heading"> 
                Date
                </th>
                <th class="heading"> 
                Process
                </th>
                <th class="heading"> 
                Curr Status
                </th>
                <th class="heading_blank"> 
                Change Status
                </th>
                <th class="heading_blank"> 

                </th>
            </tr>
            <?php
            include "config.php";
            $result=mysql_query ("SELECT * FROM `order` WHERE process='active'");
            while(($row= mysql_fetch_object ($result))!=null) {
            ?>

            <tr>
                <td class="content"> 
                <?php echo $row->sl_no; ?>
                </td>
                <td class="content"> 
                <?php echo $row->order_id; ?>
                </td>
                <td class="content"> 
                <?php echo $row->pick_date; ?>
                </td>
                <td class="content"> 
                <?php echo $row->process; ?>
                </td>
                <td class="content"> 
                <?php echo $row->status; ?>
                </td>
                <form action="update_status.php?order_id=<?php echo $row->order_id; ?>" method="POST">
                <td>
                <div class="select-style">              
                <select name="status">
                    <option value="<?php echo $row->status; ?>"><?php echo $row->status; ?></option>
                    <option value="Step_1">Step_1</option>
                    <option value="Step_2">Step_2</option>
                    <option value="Step_3">Step_3</option>
                    <option value="Step_4">Step_4</option>
                </select>
                </div>
                </td>
                <td> 
                <input type="submit" class="order_details_btn" value="Change">
                </td>
                </form>
                </tr>
            <?php } ?>
            </table>
        </div>
        <body>
</html>

这里的提交表单可以正常工作,但不在上一页中

【问题讨论】:

  • 不起作用根本没有帮助。检查控制台,看看是否出现任何错误。
  • isset($_POST['checked_box']); 你的复选框在哪里??
  • 很有可能它不起作用,因为&lt;form&gt;&lt;/form&gt; 部分位于无效的HTML 部分中。尽可能不要在表格中打开表格,当然也不应该在单元格之间打开。

标签: php jquery


【解决方案1】:

尽管 HTML 无效,但表单确实在至少两个浏览器中提交并生成警报。修复 HTML,使表单位于 TD 元素内并重新测试:

            <td>
            <form action="update_status.php?order_id=<?php echo $row->order_id; ?>" method="POST">
            <div class="select-style"  style="float: left; margin-right: 10px">              
            <select name="status">
                <option value="<?php echo $row->status; ?>"><?php echo $row->status; ?></option>
                <option value="Step_1">Step_1</option>
                <option value="Step_2">Step_2</option>
                <option value="Step_3">Step_3</option>
                <option value="Step_4">Step_4</option>
            </select>
            </div>
            <input type="submit" class="order_details_btn" value="Change">
            </form>
            </td>

请参阅this answer,了解如何在不同浏览器中查看控制台,并在需要时将报告的任何错误添加到您的问题中。

【讨论】:

  • 您的答案中的代码还包含无效的 HTML,其中 &lt;form&gt;&lt;/form&gt; 标记跨越两个 td 容器。
猜你喜欢
  • 1970-01-01
  • 2014-02-16
  • 2014-01-18
  • 2019-01-03
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多