Struts Ajax 请求耗时较长

Struts Ajax request taking long time

我正在使用 Struts ajax 调用来显示 JSP

中的数据
<sx:a id="testReport" formId="testform" targets="testdiv">

此请求需要很长时间time.Could 如果有办法显示加载图像或模糊屏幕直到 Struts AJAX 请求完成,请有人帮助我。

您还没有显示您的 ajax 电话
假设 ajax 调用应该是这样你可以尝试:
在发出 ajax 请求之前显示图像,并在 Ajax 调用完成后隐藏它

$('#loading-image').show();
$.ajax({
    url: uri,
    success: function(html){
        // Code here after success
    },
    complete: function(){
        $('#loading-image').hide();
    }
});

您还可以在图像后面显示 Modal Div,这样用户在 Ajax 通话进行时无法与页面互动:

<div id="myModal" class="modal">

</div>

css 为您的 模态 div

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

顺便说一句: 这是通过使用 jQuery 和 css 而不是 完成的struts 问题

更新:

确定您正在使用 struts-dojo plugin
那就看看这个
你要找的是indicator属性,我觉得是:

<img id="loadingImage" src="images/loadingAnimation.gif" style="display:none"/>
<sx:a id="testReport" formId="testform" targets="testdiv" showLoadingText="false" indicator="loadingImage">

这篇link会对你有帮助AjaxandJavaScriptRecipes-Showindicatorwhilerequestisinprogress