收到 AJAX 结果后加载器没有消失
Loader not disappearing after AJAX result is received
我有一个通过 AJAX 显示数据的页面,直到获取结果时我希望显示一个加载器,一旦获取结果我希望加载器应该消失。下面是我试图显示加载程序的代码的一部分
var onSubmit = function(e)
{
var txtbox = $('#txt').val();
var hiddenTxt = $('#hidden').val();
$("#walkaway").hide();
$("#submitamt").hide();
$("#xtrabutton").hide();
LodingAnimate();
$.ajax(
{
type: 'post',
url: 'test2.php',
dataType: 'json',
data: {txt: txtbox,hidden: hiddenTxt},
cache: false,
success: function(returndata)
{
$('#first').html(returndata[0]);
$('#second').html(returndata[0]);
$('#third').html(returndata[0]);
},
error: function()
{
console.error('Failed to process ajax !');
}
});
function LodingAnimate()
{
$("#maillist").html('<img src="img/ajax-loader.gif" /> Please Wait Loading...');
}
};
点击一个按钮,上面的 AJAX 被执行,点击后加载程序运行但即使在我得到回复(在控制台中)加载程序继续 运行,但实际上它应该已经消失了。
你应该在 ajax 调用完成后手动 hide/remove 加载程序,添加 Jquery Complete
回调并添加代码以删除其中的加载程序。
Jquery Complete - 此回调将在成功和错误回调执行后执行。
$.ajax(
{
type: 'post',
url: 'test2.php',
dataType: 'json',
data: {txt: txtbox,hidden: hiddenTxt},
cache: false,
success: function(returndata)
{
//Success code
},
error: function()
{
//error code
},
complete:function()
{
//This block will execute after success/error executes.
//Make the loader div empty
$("#maillist").empty();
}
});
我有一个通过 AJAX 显示数据的页面,直到获取结果时我希望显示一个加载器,一旦获取结果我希望加载器应该消失。下面是我试图显示加载程序的代码的一部分
var onSubmit = function(e)
{
var txtbox = $('#txt').val();
var hiddenTxt = $('#hidden').val();
$("#walkaway").hide();
$("#submitamt").hide();
$("#xtrabutton").hide();
LodingAnimate();
$.ajax(
{
type: 'post',
url: 'test2.php',
dataType: 'json',
data: {txt: txtbox,hidden: hiddenTxt},
cache: false,
success: function(returndata)
{
$('#first').html(returndata[0]);
$('#second').html(returndata[0]);
$('#third').html(returndata[0]);
},
error: function()
{
console.error('Failed to process ajax !');
}
});
function LodingAnimate()
{
$("#maillist").html('<img src="img/ajax-loader.gif" /> Please Wait Loading...');
}
};
点击一个按钮,上面的 AJAX 被执行,点击后加载程序运行但即使在我得到回复(在控制台中)加载程序继续 运行,但实际上它应该已经消失了。
你应该在 ajax 调用完成后手动 hide/remove 加载程序,添加 Jquery Complete
回调并添加代码以删除其中的加载程序。
Jquery Complete - 此回调将在成功和错误回调执行后执行。
$.ajax(
{
type: 'post',
url: 'test2.php',
dataType: 'json',
data: {txt: txtbox,hidden: hiddenTxt},
cache: false,
success: function(returndata)
{
//Success code
},
error: function()
{
//error code
},
complete:function()
{
//This block will execute after success/error executes.
//Make the loader div empty
$("#maillist").empty();
}
});