1

i have a jquery ajax request. On page load a loading-image is displayed. this is working well, but i want to display the loading gif for a minimum of 1 second.

I've already tried this: Ajax loader image: How to set a minimum duration during which the loader is shown? , but it's not working.

My code is:

<div id="ajaxcontent"><img src="loader.gif" id="ajaxloading" /></div>

and

$.ajax({
// some code for the request
success: function () {
             $('#ajaxcontent').text(myResultText);
        }

I've also tried to add .delay(1000) before the text is shown, but this also does not work.

2 Answers 2

2

did you try this ?

   setTimeout(function() { $('#ajaxcontent').text(myResultText);},
               1000);
Sign up to request clarification or add additional context in comments.

Comments

1

The delay() method in jQuery relates to animations, so it won't delay the updating of any properties of an element. Instead, try using the setTimeout() function, which runs the code you specify after waiting for a set number of miliseconds:

$.ajax({
    // some code for the request
    success: function () {
        setTimeout(function() {
            $('#ajaxcontent').text(myResultText);
        }, 1000);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.