Click here to Skip to main content
15,914,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to show modal while process start and hide when process complete, but it is not show for proper time, it just blink (show and hide for very small duration) my code is given below

What I have tried:

function loadShipment() {
       var Year = $("#year").val();
       var Month = $("#month").val();
       var DataObjectForAjaxCall = { strYear: Year, strMonth: Month };
       if (Year != "" && Month != "") {
           $("#modalCenter").click(); // Show modal
           $.ajax({
               url: "@Url.Action("loadShipment", "ManualBooking")",
               method: "GET",
               data: DataObjectForAjaxCall,
               async: false,
               success: function (Result) {
                   $('.modal-body').html(Result);
               }
           });
           $("#hideLoader").click(); // Hide modal
       } else {
           Alerts("Select Year and Month First");
       }

   }
Posted
Updated 4-Jul-17 23:04pm

1 solution

This bit here:
JavaScript
$.ajax({
      url: "@Url.Action("loadShipment", "ManualBooking")",
      method: "GET",
      data: DataObjectForAjaxCall,
      async: false,
      success: function (Result) {
           $('.modal-body').html(Result);
      }
});


is asynchronous. You tell it what do to and it goes off and runs.

The next line:
JavaScript
$("#hideLoader").click(); // Hide modal

runs just after you tell the ajax call what to do, not when it completes. That happens elsewhere.

Once the async ajax call has been complete, it runs this:
JavaScript
success: function (Result) {
     $('.modal-body').html(Result);
}

but only if it succeeds.

Add your hide in there.

Also include an
JavaScript
error: function () {
        
}

to catch when the process failed. You don't want the modal item to remain if the process failes
 
Share this answer
 
Comments
Member 10028394 5-Jul-17 5:26am    
I could not understand ur answer, please told me clearly where i take mistake or if you have any sample code please post here.
Thanks
Andy Lanng 5-Jul-17 5:30am    
I have told you clearly exactly where your mistake is and clearly and exactly how to fix it.

Anything you want to happen after the successful ajax call, put in the success function
Anything you want to happen after an unsuccessful ajax call, put in the error function

Anything you want to happen after other success for error, add to both functions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900