Jquery Block ui仅显示在函数的ajaxStart上

时间:2010-02-19 01:04:28

标签: jquery ajax loading blockui

我正在使用Blockui来阻止页面,并在执行ajax函数时显示加载gif。见这里:

$(document).ready(function() { 
            //shows loading screen whilst posting via ajax
    $().ajaxStart(function() { 
        $.blockUI({ message: '<h1><img src="../images/layout/busy.gif" /> Just a moment...</h1>' });  });           
    $().ajaxStop($.unblockUI);                     

//Load table from table.php
//Timestamp resolves IE caching issue
var tsTimeStamp= new Date().getTime();
$.get('table.php',
      {action: "get", time: tsTimeStamp},
      function(data){
        $('#customertable').html(data).slideDown('slow');
      });
return true;                           

});

我的问题是每次执行ajax函数时都会阻止页面。如何仅在执行某些功能时才显示

1 个答案:

答案 0 :(得分:2)

您必须根据具体情况从通用ajaxStart和ajaxStop事件中阻止/取消阻止并阻止/取消阻止:

$.blockUI({ message: '<h1><img src="../images/layout/busy.gif" /> Just a moment...</h1>' });
$.get('table.php',
      {action: "get", time: tsTimeStamp},
      function(data){
        $.unblockUI();
        $('#customertable').html(data).slideDown('slow');
      });