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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:47:11+00:00 2026-06-15T16:47:11+00:00

Hi I am making one site in RubyOnRails. I am having problem in showing

  • 0

Hi I am making one site in RubyOnRails. I am having problem in showing some content at client side. What I want to do is like news where after every 10 sec., news would change. What I have done is I have make an ajax which fetch the news from my server, server returns array in json response. Now I have all the news array at client side I want to show one by one in 10 sec interval.
I have tried with this code but its not showing anything except last news.

function get_news(){
    $.ajax({
          url : "my.json",
          success:function(data){
              // data is array of json like [{"html" : "dfsf"},{"html":"ddd"}]
              news_change(data);
          }
    });
}

get_news();

function news_change(feed){
    $.each(feed,function(index,f){
        var feed_html = f.html;
        $('#news_div').fadeOut('slow', function(){
          $('#news_div').html(feed_html);
          $('#news_div').fadeIn('slow');
        });
        sleep(10000);
    });
}

function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds){
          break;
        }
    }
}

when I execute this code it only shows news which is last. And also it hang my browser. Please suggest me why is this because ?

  • 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-15T16:47:12+00:00Added an answer on June 15, 2026 at 4:47 pm

    Use setTimeout or setInterval, which execute code asynchronously after a certain number of milliseconds. Looping is synchronous and locks the browser while it executes.

    // this will execute get_news every 10,000 ms
    var newsInterval = setInterval(get_news, 10000);
    
    // if you ever want to stop the interval, use clearInterval
    clearInterval(newsInterval);
    

    Note that get_news performs an ajax call, which could take some time, meaning that your news will not update exactly every 10 seconds.

    EDIT: to iterate through the news array every 10 seconds, you’d pass the news_change function to setInterval:

    var newsInterval;
    
    function get_news(){
        $.ajax({
            url : "my.json",
            success:function(data) {
                newsInterval = setInterval(function () {
                    news_change(data);
                }, 10000);
            }
        });
    }
    
    get_news();
    
    // if you ever want to stop the interval, use clearInterval
    clearInterval(newsInterval);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making some basic site with Twitter Bootstrap I have one div and two
I'm making my first site with Django, and I'm having a database design problem.
I'm making an avatar site. One of my users is having an issue... their
In all of the http examples for Netty the client is making just one
I'm building a one-page(one file) site and want to get insight as to whether
I'm working on making a modification to a site built with ASP/C#, and one
making a multi-language site with codeginiter. I have created two folders. One for french
I'm making a responsive site and need to include a Facebook Like-Box for the
I'm making an App Engine site that I don't want to be nationwide, but
I am making a site in JRuby on Rails, I am using some Java

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.