Kiran
Kiran

Reputation: 366

Struts Ajax request taking long time

I am using Struts ajax call for displaying data in JSP

<sx:a id="testReport" formId="testform" targets="testdiv">

This request is taking long time.Could you someone help me if there is a way to show loading image or blur the screen until Struts AJAX request is completed.

Upvotes: 1

Views: 191

Answers (1)

Shantaram Tupe
Shantaram Tupe

Reputation: 1666

You have not shown your ajax call
Assuming ajax call should be like this you can try:
Show Image before making the ajax request, and hide it after Ajax call completes

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

You can also show Modal Div behind your image so user can not interact with page while Ajax call is going on:

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

</div>

css for your modal 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 */
}

BTW: this is done by using jQuery and css not a struts issue

UPDATE:

OK You are using struts-dojo plugin
Have look at this then
You are looking for indicator attribute, I think so:

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

This link will help you AjaxandJavaScriptRecipes-Showindicatorwhilerequestisinprogress

Upvotes: 2

Related Questions