显示spinner.gif在Ajax调用在Grails的加载时间加载、时间、gif、spinner

2023-09-10 13:35:38 作者:不是所有的故事都有后来

喜  我正在开发中的Grails Web应用程序,它使用大量ajax.I的需要出示spinner.gif图像在处理AJAX request.My样品GSP code为

Hi I am developing a web application in grails which uses lot of ajax.I need to show a spinner.gif image while processing the ajax request.My sample gsp code is

<div id="ajax-area">
  <g:remoteLink action="list" controller="file" update="ajax-area">
    view files
  </g:remoteLink>
</div>

在上面的code如果我们点击查看文件链接,它会更新Ajax的区域股利。

In the above code if we click on the view files link it will update the ajax-area div.

能否有人告诉我如何与spinner.gif上加载AJAX更新Ajax的区域。

Could some one show me how to update the ajax-area with spinner.gif on loading ajax.

感谢

推荐答案

假设你使用的原型,你可以添加一些像这样的页面(或布局)来显示一个微调:

Assuming that you use Prototype, you can add something like this to the page (or the layout) to show a spinner:

<script type="text/javascript">
Ajax.Responders.register({
   onCreate: function() {
      if($('ajax-area'))
         $('ajax-area').update('<img src="${createLinkTo(dir:'images',file:'spinner.gif')}" border="0" alt="Loading..." title="Loading..." width="16" height="16" />');
   }
});
</script>

它覆盖AJAX区域元素将在启动Ajax调用的内容。

It overwrites the content of the 'ajax-area' element when the Ajax call is initiated.