Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:44:42+00:00 2026-06-17T19:44:42+00:00

I have a jquery ui dialog that is ajax loaded with a partial view

  • 0

I have a jquery ui dialog that is ajax loaded with a partial view from the server. The dialog initially opens as a dialog-ajax-loader and when the call returns it animates/grows to the size of the content.

The problem is when the dialog content gets cached or the ajax call is too fast, I get an undesirable effect where the content is loaded basically right away into the ajax-loader-sized dialog, without the ajax loader actually being visible even for a moment. Needless to say, with all the work I put in to make this look amazing, I can’t settle for this. I need the ajax loader to display for 1 second minimum, or more if the ajax call actually takes more.

I’ve searched the web for quite a while trying to find a nice sleep() function but there’s always a taboo attached. Wanted to post here to get some ideas whats the best way to do this.

The actual code is of course a lot more complicated, but conceptually is follows like this:

 var mydialog = $("<div></div>").dialog({...Ajax loader settings...});

 var minimumTimeMet = false;
 setTimeout(function( ){ minimumTimeMet = true; }, 1000);
 mydialog.dialog("open"); //Open ajax loader

 $.ajax({ 
     cache: false,   //This helps but not always, sometimes the request is just too fast
     ....
     success: function(htmlContentResponse){

          while(!minimumTimeMet){
              //sleep here! However, thread cannot be 
              //blocked because the function set in setTimeout
              //above must executed to change minimumTimeMet = true 
              //and break out of this loop. 
          }

          mydialog.html(htmlContentResponse);  
          mydialog.animate({...Animate into new dialog settings ...});
     }

 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:44:43+00:00Added an answer on June 17, 2026 at 7:44 pm

    Try adding a flag before firing the request and at the same time setTimeout of 1000ms and clear the flag in the callback

    var flag = false;
    var response;
    
    setTimeout(function () {
        flag = true;
        if (response) {
            ajaxCallback(response);
        }
    }, 1000);
    
    $.ajax({
        cache: false,
        success: function(htmlContentResponse){
            response = htmlContentResponse;
            if (flag)   {
                ajaxCallback(response);
            }
        }
    });
    
    function ajaxCallback(htmlContentResponse) {
        // Do something
    }
    

    This way, if the ajax call is finished early, it will wait till the setTimeout callback is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery dialog box that opens and then an AJAX call is
I have a jquery modal dialog that displays a partial view. The partial view
I have the following Jquery that returns values from a dialog Box and fills
I have an Ajax control that is loaded into a Yahoo popup using jQuery.
I have a dialog window that uses a URL for its contents { function(){jQuery.ajax({'success':function(html)
I want to create a jQuery dialog from HTML returned by an AJAX call.
I have a jQuery dialog that loads its content trough ajax after its opened.
I have a jQuery dialog that appears and loads an external page. In that
When creating or editing object sin my table, I have a jquery dialog that
I have a jQuery UI Dialog that gets displayed when specific elements are clicked.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.