【问题标题】:IE double submits data when executing scriptIE执行脚本时双重提交数据
【发布时间】:2014-05-07 19:32:27
【问题描述】:

在 Jquery /Ajax 方面需要一点帮助。

我在一页中有多个表单,一旦单击其中一个,它将数据发送到 post.php ++ 禁用提交按钮。 我为此使用以下脚本。

<script>
$(function () {
$('form').on('submit', function (e) {
    $.ajax({
        type: 'post',
        url: 'post.php',
        data: $(this).serialize(),
        success: function (returnedData ) {
         $( '#sidebar' ).load( 'div.php');

        }
    });
    e.preventDefault();
    });
});

</script>

<script>
    $(document).ready(function () {
    $('input[type=submit]').click(function () {
            $(this).prop("disabled", true);
            $(this).val( "Selected" );
              $(this).closest('form').trigger('submit');
                 });
    });
</script>

我面临的问题是它适用于所有浏览器,除了 IE9。 (它双重提交数据......)。如何将两个脚本合并为一个?我面临的问题是它适用于除 IE9 之外的所有浏览器。 (它双重提交数据......)。如何将两个脚本合并为一个? (请注意,我在此页面中至少有 50 个表单......)**

【问题讨论】:

    标签: php jquery ajax


    【解决方案1】:

    使用它来防止重复提交

    <input type="submit" onclick="return false; " />
    

    要合并这两个脚本,只需执行以下操作:

    <script>
    $(function () {
    $('input[type=submit]').click(function () {
      e.preventDefault();
      e.stopPropagation();
    
      $(this).prop("disabled", true);
      $(this).val( "Selected" );
    
      $.ajax({
            type: 'post',
            url: 'post.php',
            data: $(this).parents('form:first').serialize(),
            success: function (returnedData ) {
             $( '#sidebar' ).load( 'div.php');
    
            }
        });
    });
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-19
      • 2019-07-08
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      相关资源
      最近更新 更多