weixin_33739523 2015-07-16 15:19 采纳率: 0%
浏览 45

求助:Ajax- beforeSend

为了防止出现两次错误,我使用了“发送前”的代码:

hasSent = false

function submit() {
    if (!hasSent)
        $.ajax({
            url: "${createLink(controller:'userInvitation', action:'ajaxUpdate')}",
            type: "POST",
            data: $("#invitationForm").serialize(),
            success: function(data, textStatus, jqXHR) {
                $('#invitationForm')[0].reset();
                $('.thank-you-modal').modal('show');
                hasSent = true;
                console.log(hasSent)
            },

            complete: function() {
                hasSent = false;
                console.log(hasSent)
            }
        });
}

如你所见,只有当hassent=false时,Ajax才会发生。由于某些原因,如果用户在Submit按钮上单击多次(非常快),Ajax也会发生。

  • 写回答

3条回答 默认 最新

  • 胖鸭 2015-07-16 15:23
    关注

    To prevent this kind of issue disable the button before sending the ajax and then anable inside the success function

    $(mybutton).prop("disabled",true);
    // ajax call here
    

    then

    success: function(data, textStatus, jqXHR) {
        $(mybutton).prop("disabled",false);
        // code here
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable