gpt4 book ai didi

javascript - 无法弄清楚为什么这个 ajax 请求会触发两次

转载 作者:行者123 更新时间:2023-11-29 18:16:02 26 4
gpt4 key购买 nike

我正在处理这段代码,但我无法弄清楚为什么在我单击所选按钮时 ajax 请求会触发两次:

   $('#passwd-nuova').blur(function() {
var response = $('#passwd-nuova').validate({
'classeform': 'form-utenti',
'empty': 'passwd-nuova'
});
if (!response.empty) {
$('#reset').addClass('btn-disabled');
} else {
$('#reset').removeClass('btn-disabled');
/*
* RESET PASSWORD PANNELLO
*/
$('#reset').on('click', function() {
var new_passwd = $('input[name=passwd-nuova]').val();
var selezionato = $(this).loadID({
'nometabella': 'utenti',
'abbr': 'utenti'
});
var send_email = $('#cb-email').prop('checked');
$.ajax({
cache: false,
type: "POST",
url: "/gutenti/",
dataType: "json",
data: {
'mod-passwd': true,
'idu': selezionato,
'new-passwd': new_passwd,
'send-email': send_email
},
success: function(response) {
var tab = $("#datatable_utenti").dataTable();
$('#modal-reset').modal('hide');
tab.fnDraw();
$(window).scrollTop(0);
$(document).genAlert({
tipo: 'success',
msg: 'modifica completata con successo',
time: 800
});
$('input').each(function() {
$(this).val('');
});
$("#datatable_utenti tbody").compileForm({
'abbr': 'utenti',
'nometabellaDB': 'admin_utenti',
'nometabella': 'utenti'
});
$(document).stato(profile, 'base');
return;
},
error: function() {
console.log("errore async");
$('#modal-reset').modal('hide');
$(window).scrollTop(0);

$(document).genAlert({
tipo: 'error',
msg: 'qualcosa è andato storto, riprova',
time: 800
});
}
});
return;

});
}

});

我尝试在调用后禁用按钮,并且不返回任何内容以退出该函数,但没有任何效果。

最佳答案

您的 $('#passwd-nuova').blur 处理程序多次绑定(bind) $('#reset').click' 处理程序。

很高兴我的评论对您有所帮助 ;)

关于javascript - 无法弄清楚为什么这个 ajax 请求会触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com