2016-05-17 44 views
1

我試圖顯示引導模態消息,而jQuery重新新鮮數據到我的幾個DIV(然後隱藏它)。數據刷新確定。但是,模態會立即閃爍。jQuery顯示/隱藏引導模式在Dataload

這也是這種情況,當我只使用一個簡單的加載器GIF圖像,而不是模式。不知道我做錯了什麼。模式(或gif)需要保留,直到數據完全刷新。

在此先感謝您的幫助!

JS代碼:

$('.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

可以複製上的jsfiddle一樣,http://jsfiddle.net – dreamweiver

回答

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 

     }    
    }); 
}); 

我不能測試它,所以讓我kwow

+0

完美!非常感謝。 – penncomm