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 6978079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:42:34+00:00 2026-05-27T17:42:34+00:00

I am making a Testimonial rotator with Jquery for my website, but the Ajax

  • 0

I am making a Testimonial rotator with Jquery for my website, but the Ajax function runs too early, so you see the HTML change, then it fades out, and back in. I’ve tried to figure out the problem, but I can’t seem to find it.

<div class="testimonials">
    <div id="testimonial"></div>
</div>
<script type="text/javascript">
    function loadTestimonial(){
        $("#testimonial").fadeOut(1000);
        $.ajax({
            url: "r/get_testimonial.php",
            cache: false,
            async: false,
            timeout: 1000,
            success: function(html){
                $("#testimonial").html(html);
            },
          });   
          setTimeout($("#testimonial").fadeIn(1000), 2000);
      } 
      $(document).ready(function(){
        loadTestimonial();
        setInterval (loadTestimonial, 5000) 
      });
</script>
  • 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-05-27T17:42:34+00:00Added an answer on May 27, 2026 at 5:42 pm

    Try this code:

    <div class="testimonials">
        <div id="testimonial"></div>
    </div>
    <script type="text/javascript">
        function loadTestimonial(){
            $("#testimonial").fadeOut(1000, function(){
                $.ajax({
                    url: "r/get_testimonial.php",
                    cache: false,
                    async: false,
                    timeout: 1000,
                    success: function(html){
                        $("#testimonial").html(html).fadeIn(1000);
                    },
                  });   
            });
          } 
          $(document).ready(function(){
            loadTestimonial();
            setInterval (loadTestimonial, 5000) 
          });
    </script>
    

    What went wrong with your code? The ajax code was called imidiatly which will replace the old HTML when it is ready, what I do above is wait for the callback of the fadeOut() and then trigger the Ajax function. Which will get the source and fadeIn the new HTML.

    You might think it’s an sync function (because the Ajax had async: false), but the jQuery fadeOut is also async, so you can not wait for that the way you did.

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

Sidebar

Related Questions

Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
making an infinite loop in javascript, and jQuery... this is my current code: $(#bg2).css({opacity:
Making good progress on rails now, but hit a snag on heroku deployment. After
Making a quick JQuery demo where clicking a table element changes it from black
Making this tutorial: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html I have ListActivity-derived class and onCreateContextMenu, onContextItemSelected overrides. I think
Making a left hand side menu for my website. Should I create a Unordered
Making an ajax call to return some data from the server. The data comes
Making a SMS App and it is going well so far, but ran into
I making a slider for both modern browsers and old browsers too. I use

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.