chenpeng

Ajax防止重复点击(避免重复数据提交)
|´・ω・)ノ分享一个Ajax的防止重复点击beforeSend这是函数的意思提交中在这个函数中把点击的按钮禁用掉...
扫描右侧二维码阅读全文
26
2019/02

Ajax防止重复点击(避免重复数据提交)

|´・ω・)ノ分享一个Ajax的防止重复点击beforeSend这是函数的意思提交中在这个函数中把点击的按钮禁用掉或者加入别的,
complete是提交完成后操作的在这个函数中加入去掉禁用按钮的js这个就能防止重复提交

$.ajax({
type: "post",
data: studentInfo,
contentType: "application/json",
url: "/Home/Submit",
beforeSend: function () {
    // 禁用按钮防止重复提交
    $("#submit").attr({ disabled: "disabled" });
},
success: function (data) {
    if (data == "Success") {
        //清空输入框
        clearBox();
    }
},
complete: function () {
    $("#submit").removeAttr("disabled");
},
error: function (data) {
    $("#submit").removeAttr("disabled");
}
});
Last modification:February 26th, 2019 at 09:26 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment