【问题标题】:Firefox does not submit my formFirefox 没有提交我的表单
【发布时间】:2013-04-28 00:28:33
【问题描述】:

我有一个 php 应用程序,它从 mysql 数据库中获取请求并显示它们以供进一步批准。该表单从send_req.php 获取,并显示在showrequests.php 的div 内。这是send_req.php的代码

<table style="border:0;border-color:transparent">
<tr style="background-color:lightblue">
<td>Product ID</td>
<td>Name</td>
<td>Quantity</td>
<td><input type="checkbox" name="selectAll" /></td>
<td>Authorized Quantity</td>
</tr>
<form method="post" action="send_req.php">
<?php
$reqNum = $_POST['rId'];
echo "<h3>Request # $reqNum</h3>";

$showReqs = mysql_query("Select * from request where request_number='".$reqNum."' and status=0");
    while($resultA = mysql_fetch_array($showReqs))
    {
        $rBy = $resultA['requested_by'];
        $rTime = $resultA['request_time'];
        $rId = $resultA['id'];
        $pId = $resultA['product_id'];
        $getPrName = mysql_query("select name from products where id='$pId'");
        $prN = mysql_fetch_array($getPrName);
        $prName = $prN['name'];
        $rQuantity = $resultA['requested_quantity'];
        $status = $resultA['status'];

?>
    <tr>
        <input type="hidden" name="rId[]" value="<?php echo $rId; ?>"/>
    <td style="background-color:orange"><input type="text" name="prId[]" value="<?php echo $pId; ?>" readonly="readonly" style="border:0px"/></td>
    <td style="background-color:orange"><input type="text" name="prName[]" value="<?php echo $prName; ?>" readonly="readonly" style="border:0px"/></td>
    <td style="background-color:orange"><input type="text" name="quantity[]" value="<?php echo $rQuantity; ?>" readonly="readonly" style="border:0px"/></td>
    <td style="background-color:orange"></td>
    <td><input type="text" name="pQuantity[]" /></td>
    </tr>
<?php }
?>
    <tr>
<td></td>
<td></td>
<td></td>
<input type="hidden" name="rNum" value="<?php echo $reqNum; ?>" />
<td></td>
<td><input type="submit" name="submitReq" value="Send" id="submit_req" style="backgroundColor:Transparent;border:0;color:blue;width:100;"/></td>
</tr>
</form>
</table>
<?php
echo "Requested By:$rBy at ".substr($rTime,11,18)." ".substr($rTime,0,10);
?>

这是showrequests.php 页面

<html>
<head>
<script type="text/javascript">
function getRequest(ob)
{
    var id = ob.id;
    if(window.XMLHttpRequest)
{
    ajaxOb = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
    ajaxOb = new ActiveXObject("Microsoft.XMLHTTP");
}  
     ajaxOb.open("POST", "send_req.php");   
     ajaxOb.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                    
     ajaxOb.send("rId=" + id);  
     ajaxOb.onreadystatechange = function()  
    {  
        if(ajaxOb.readyState == 4)
        {
            if(ajaxOb.status == 200)
            {
                document.getElementById("showTable").innerHTML = ajaxOb.responseText;
            }
        }

    }  
}
</script>
</head>
<body>
<?php
$mysql_con = mysql_connect("localhost","root","") or die("Could not connect ".mysql_error());
$mysql_db = mysql_select_db("cart",$mysql_con) or die("Unable to select db ".mysql_error());
echo "<h2 align='center'>Pending Requests</h2>";
$showReq = mysql_query("Select distinct(request_number) as rNums from request where status=0");
?>
<div style="float:left;margin-right:15px;">
<br/>
<?php
while($result = mysql_fetch_array($showReq))
{
    $rNum = $result['rNums'];
?>
<input type="button" name="fetchReq" id="<?php echo $rNum; ?>" value="<?php echo "Request # $rNum"; ?>" style="margin-bottom:5px;backgroundColor:Transparent;border:0;color:blue;width:100;text-Decoration:underline" onclick="getRequest(this)"/>

<?php
    echo "<br/>";
}
?>
</div>
<div id="showTable" style="float: left">
</div>
</body>
</html>

我现在的问题是在 chrome 和 IE 中一切正常,但是当我单击 firefox 中的提交按钮时,表单没有提交。我正在使用 Firefox 20.0.1。更新:我从send_req.php 中删除了html,head and body 标签 还是不行

【问题讨论】:

  • 请仔细阅读本网站的常见问题部分。它明确建议您发布只发布相关的代码,所有可能与问题相关的信息(如:检查您的控制台是否为FF),并展示您自己的一些努力导致问题。另外:停止在 php 中使用 mysql_*,因为它已被弃用
  • 您可能正在使用非常非常非常古老的 Firefox。尝试将其更新到最新版本并再次检查。我在您的 ode 中没有看到任何错误
  • 如果这是一个公开的表格,你有一个相当大的问题。在将输入输入到 sql 查询之前,您没有对其进行清理,这使得它为 sql 注入黑客敞开了大门。
  • 清理你的代码,只显示相关部分,我找不到你的开头&lt;form&gt; 行来挽救我的生命(如果你觉得有必要显示整个东西,链接一个粘贴箱,但请,只显示相关部分
  • 如果某个答案确实解决了您的问题,请将其标记为接受未来访问者!

标签: php javascript html ajax firefox


【解决方案1】:

表格内不允许有表格。另请参阅 Form inside a table

问候, 迈克尔

【讨论】:

  • 你知道什么。我把表格放在表格里,它可以工作。我也修复了html问题。将 div 放入体内。非常感谢
【解决方案2】:

提醒:HTML 文档的结构是:

<!-- No div before html tag -->
    <!DOCTYPE html> <!-- Doctype for HTML5 ; use whatever doctype you need -->
    <html>
        <head>

        </head>

        <!-- No div before body tag -->
        <body>
             <!-- Divs only belongs here -->
        </body>    
    </html>
<!-- No div after html tag -->

如果您不遵循此基本结构,您将强制浏览器解释您的无效代码(+ 不提供文档类型时的怪癖模式)。

有些浏览器可以很好地猜出您尝试做什么,而其他浏览器则不会,就像 Firefox 一样。

请使用 HTML 验证器 W3's validator 来检查您的语法。

【讨论】:

  • 我修复了您指出的问题。另外,我将表格放在表单标签内。感谢您的帮助
猜你喜欢
  • 2014-04-08
  • 2021-08-07
  • 1970-01-01
  • 2021-04-02
  • 1970-01-01
  • 2010-10-11
  • 2018-07-09
相关资源
最近更新 更多