gpt4 book ai didi

jquery - 我如何确定脚本是否正在使用 jQuery 在 Ajax 中加载?

转载 作者:行者123 更新时间:2023-12-01 06:39:35 24 4
gpt4 key购买 nike

我如何确定脚本是否正在使用 jQuery 在 Ajax 中加载,例如我正在使用以下 jQuery/AJAX。

$('#select-countries').change(function(){
var countryId = $(this).val();
$.ajax({
type: 'POST',
url: 'process.php',
data: 'countryId='+countryId,
success: function(states){
if(states == 'null') {
$('#select-states-container').html(emptyState);
} else if(states == '0') {
$('#select-states-container').html(chooseState);
} else {
$('#select-states-container').html(states);
}
}
});
});

现在根据加载状态我想显示一条消息或显示一个加载gif,我想知道是否有ajax状态,如加载中,完成时?

最佳答案

我所做的是在ajax调用之前弹出一个加载对话框,然后使用ajax#complete()将其删除或更改消息:

$.ajax({
type: 'POST',
url: 'process.php',
data: 'countryId='+countryId,
beforeSend: function(jqXHR, settings) {
// show the awesome dialog
},
complete: function(jqXHR, textStatus) {
// remove the awesome dialog
},
error(jqXHR, textStatus, errorThrown) {
// post the not so awesome message in the awesome dialog
},
success: function(states){
if(states == 'null') {
$('#select-states-container').html(emptyState);
} else if(states == '0') {
$('#select-states-container').html(chooseState);
} else {
$('#select-states-container').html(states);
}
// change the message in the awesome dialog???
}
});

关于jquery - 我如何确定脚本是否正在使用 jQuery 在 Ajax 中加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6861603/

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