我正在尝试显示一个引导模式消息,而jQuery正在将数据重新刷新到我的几个DIV中(然后隐藏它)。数据令人耳目一新。但是,模态会立即闪烁。
当我只使用简单的加载器GIF图像而不是模态时也是这种情况。不确定我做错了什么。模态(或gif)需要保持不变,直到数据完全刷新。
提前感谢您的帮助!
JS CODE:
$('.container').on('click', '.markAttend', function(event, ui) {
myApp.showPleaseWait(); //this calls the modal to display
event.preventDefault();
var contactID = $(this).attr('contactID');
var eid = <?php echo $eid ?>;
$.ajax({
url: 'functions-ajax.php',
type: 'post',
data: 'action=markAttend&contactID=' + contactID + "&eid=" + eid, //send a value to make sure we want to destroy it.
success: function(data){
$("#searchlist").load(location.href + " #searchlist"); //Refresh list
$("#attendanceTotal").load(location.href + " #attendanceTotal"); //Refresh list
$("#searchinput").val(''); //clear out search input field
myApp.hidePleaseWait(); //this calls the modal to hide
}
});
});
答案 0 :(得分:1)
好吧,你需要等到load()
功能完成。
为此你需要添加一个这样的回调:
$("#searchlist").load(location.href + " #searchlist", function(){
myApp.hidePleaseWait();
});
但是,由于你有2个load
函数,需要一些更复杂的逻辑。试试这个:
$('.container').on('click', '.markAttend', function(event, ui) {
myApp.showPleaseWait(); //this calls the modal to display
event.preventDefault();
var contactID = $(this).attr('contactID');
var eid = <?php echo $eid ?>;
var counter = 0;
$.ajax({
url: 'functions-ajax.php',
type: 'post',
data: 'action=markAttend&contactID=' + contactID + "&eid=" + eid, //send a value to make sure we want to destroy it.
success: function(data){
$("#searchlist").load(location.href + " #searchlist", function(){
counter++;
if(counter === 2) myApp.hidePleaseWait(); //this calls the modal to hide
}); //Refresh list
$("#attendanceTotal").load(location.href + " #attendanceTotal", function(){
counter++;
if(counter === 2) myApp.hidePleaseWait(); //this calls the modal to hide
});
$("#searchinput").val(''); //clear out search input field
}
});
});
我无法测试它,所以让我知道