dsrbb20862 2013-04-03 12:19
浏览 43

单击后禁用提交按钮并保持POST / REDIRECT / GET工作

I use the POST/REDIRECT/GET trick to prevent refresh-resend of forms. Now I would like to disable a form submit button (after click) that should not be clicked twice. Although I tried all javascript examples I found, they all conflict with POST/REDIRECT/GET. In most cases it doesn't even submit but just redirects to itself. Any solution ? Thanks for your help.

Something I've tried and conflicts is this example:

the script first runs headers.php with this in:

if (isset($_POST['start-diff-scan']))
{
    $_SESSION['SCAN_START'] = true;

    header('HTTP/1.1 303 See Other');
    header('Location: '.APP_URL.'scan.php');
    exit;
}

and then scan.php with this form:

<form name="start-diff-scan" id="start-diff-scan" method="post">
    <button
        name="start-scan"
        id="start-scan"
        value=""
        class="start-scan btn btn-primary"
        type="submit"
        method="post">
        Start New Scan
    </button>
</form>

and works fine. but the js trick conflicts this. I added the js code at the very end of scan.php

<script>
$('#start-diff-scan').submit(function()
{
    $('#start-scan').prop('disabled', true);
});
</script>

What happens is it only redirects to the same page (scan.php) without executing anything. Thanks for all yoru answers and help so far this is great. Any ideas appreciated thanks very much

  • 写回答

7条回答 默认 最新

  • du155305 2013-04-03 12:22
    关注
    $('#start-scan').attr('disabled', true);
    

    or use

    .prop("disabled", true)
    
    $('#start-scan').prop("disabled", true)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么