当提交按钮被禁用时,PHP 重定向不起作用

标签 php javascript http header

在我的index.php 页面中,我有一个提交按钮,它获取表单数据并通过POST 将其发送到update.php 页面。在这个新页面上,对数据库进行操作,然后(使用 PHP)重定向回原始页面。这个重定向过程在 Firefox 中运行良好,但在 Chrome/IE 中似乎不起作用。

index.php文件中的相关代码:

<form name="battle" action="update.php" method="post">
<input type="radio" name="update" value="<?php print($names[0] . "+" . $names[1]); ?>" />
<input type="radio" name="update" value="<?php print($names[1] . "+" . $names[0]); ?>" />
<input type="submit" name="submit" value="Submit" />
</form>

这是我的 update.php 文件末尾的代码:

$con->close();
session_write_close();
header("Status: 200");
header( "Location: index.php" );
exit(0);

如果提交按钮在单击时禁用,则此代码在所有浏览器中工作,但我确实需要具有此功能。有谁知道如何使此重定向工作,同时仍然具有禁用按钮功能?

最佳答案

禁用表单提交上的提交按钮可能是一件棘手的事情。这对我有用:

注意:需要 >= jQuery1.6 才能工作

测试.php:

<script type="text/javascript">
$(document).ready(function ()
{
    $("form").submit(function ()
    {
        $("input[type='submit']").prop("disabled", true);
    })
})
</script>

<form name="battle" action="update.php" method="post">
    <input type="radio" name="update" value="foo" />
    <input type="radio" name="update" value="bar" />
    <input type="submit" name="submit" value="Submit" />
</form>

更新.php:

header("Status: 200");
header( "Location: index.php" );
exit(0);

?>

关于当提交按钮被禁用时,PHP 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6148391/

相关文章:

http - HTTP/1.0 响应是否需要 Content-Length header ?

php - 如何手动创建 laravel 迁移文件

javascript - 如何检查 session 对象是否包含任何对象?

javascript - 将数字包裹在 span 和 .not() 中

javascript - 在嵌套 for 循环内的 super 测试响应后修改对象的问题

json - 如何读取请求 JSON 正文以便在响应请求后使用它?

http - 如何将 http.HandleFunc 与 slugs 一起使用

javascript - 谷歌图表 : “Uncaught (in promise) Error: Unknown header type: 4.7278” error

php - MySQL 触发器 last_insert_id()

php - 自动将产品添加到购物车(某些 WooCommerce 产品类别除外)