在调用下一个Javascript函数之前,如何让浏览器更新?

时间:2010-02-02 16:15:20

标签: javascript jquery ajax oracle-apex

我在从我的函数中获取所需的功能时遇到了一些麻烦...基本上,我正在调用两个AJAX函数(由Oracle APEX提供,因此我无法更改这些函数)但是他们'需要一段时间。我想在行动进行时展示标准的AJAXy旋转gif,但我没有太多运气。这是我到目前为止所做的:

function paginate(reportIDs, startRecord)
{
 //block access to the UI and show a "please wait" message
  $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } });

  //make the two AJAX calls to the APEX provided function
  for(var i = 0;i<reportIDs.length;i++)
  {
    $a_report(reportIDs[i], startRecord, ITEMS_PER_PAGE, ITEMS_PER_PAGE);
  }

  //clean up some APEX garbage on the page
  formatPage();

  //make the "please wait" message go away
  $.unblockUI;
}

我目前遇到的具体问题是UI的阻塞似乎只有在AJAX调用完成后才会发生。然后它永远不会解锁...任何想法?

2 个答案:

答案 0 :(得分:2)

用另一种方法包裹你的ajax并将该方法延迟1 ms

function paginate(reportIDs, startRecord)
{
    //block access to the UI and show a "please wait" message
    $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        }
    });
    setTimeout(function(){
        //make the two AJAX calls to the APEX provided function
        for(var i = 0;i<reportIDs.length;i++)
        {
            $a_report(reportIDs[i], startRecord, ITEMS_PER_PAGE, ITEMS_PER_PAGE);
        }

        //clean up some APEX garbage on the page
        formatPage();

        //make the "please wait" message go away
        $.unblockUI();
   }, 1);
}

答案 1 :(得分:0)

假设调用是async - 您是否可以将回调传递给ajax报告函数或使用其他函数或常量来设置回调?否则你将不得不轮询响应 - 你将如何做到这将取决于从$a_report和/或其ajax功能背后的api返回的内容。

如果他们不是async那么它可能是一个错字或其他东西。正如另一张海报建议$.blockUI;应该是$.blockUI();