等待Ajax渲染(JSF)

时间:2011-08-19 09:17:27

标签: javascript ajax jsf primefaces wait

我有一个PRIMEFACES对话框,我使用onCloseUpdate属性在对话框关闭时重新呈现对话框的所有内容。问题是,当我关闭对话框,并(快速)单击再次打开它时,我看到onCloseUpdate尚未完成重新呈现对话框的内容,旧内容显示半秒/秒的时间段。

这是使对话框可见的命令链接:

<h:commandLink id="area1" onclick="dlg.show()">
...
</h:commandLink>

,这是对话框:

<ppctu:dialog onCloseUpdate="... here is all the component ids from the dialog content           ..."  modal="true" widgetVar="dlg">

有没有办法等待onCloseUpdate渲染完成?

提前致谢

1 个答案:

答案 0 :(得分:0)

使用同步ajax调用。同步AJAX(真正的SJAX - 同步Javascript和XML)是模态的,这意味着javascript将停止处理您的程序,直到从服务器获得结果。在处理请求时,浏览器被有效冻结。

function getFile(url) {
  if (window.XMLHttpRequest) {              
    AJAX=new XMLHttpRequest();              
  } else {                                  
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     AJAX.open("GET", url, false); //notice the 'false' attribute                           
     AJAX.send(null);
     return AJAX.responseText;                                         
  } else {
     return false;
  }                                             
}

如果您使用的是jQuery,请将async:false放入您的ajax调用中     var fileFromServer = getFile('http://somedomain.com/somefile.txt');