gpt4 book ai didi

javascript - 如何在ajax调用之前禁用某个功能,并在ajax成功时启用它?

转载 作者:行者123 更新时间:2023-12-03 11:43:41 25 4
gpt4 key购买 nike

我有一个功能在ajax功能之外,我想在ajax运行时禁用这个“启用”点击功能,并在ajax成功加载后启用它,我该如何解决这个问题?任何帮助,将不胜感激。这是我的代码:

 $('enable').click(function () {
console.log(123);
$(this).css('display', 'none');

var xhr = $.ajax({
type: "POST",
url: $.vp + "signup/distLookup.ashx" + "?first=" + val_f_name + "&last=" + val_l_name + "&country=" + val_country + "&language=" + $.langID,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);

;

最佳答案

var enable = true;
$('enable').click(function () {
if(enable) {
enable = false;
console.log(123);
$(this).css('display', 'none');

var xhr = $.ajax({
type: "POST",
url: $.vp + "signup/distLookup.ashx" + "?first=" + val_f_name + "&last=" + val_l_name + "&country=" + val_country + "&language=" + $.langID,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
enable = true;
}
});
}
});

当ajax触发时,您可以将enable设置为false。

编辑:

类似这样的事情吗?

var enable = true;
$('enable').click(function () {
if(enable) {
console.log(123);
$(this).css('display', 'none');
}
});

function callAjax() {
enable = false;
var xhr = $.ajax({
type: "POST",
url: $.vp + "signup/distLookup.ashx" + "?first=" + val_f_name + "&last=" + val_l_name + "&country=" + val_country + "&language=" + $.langID,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
enable = true;
}
});
}

关于javascript - 如何在ajax调用之前禁用某个功能,并在ajax成功时启用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26149982/

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