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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:29:26+00:00 2026-06-11T08:29:26+00:00

I have such problem: I want to show counter, which will be changing every

  • 0

I have such problem: I want to show counter, which will be changing every second, so I need to change Ruby variable, which I will be using in jQuery.

EDIT: I want to make counter, that will be the same for all users.

I have counter.json.erb file:

 {
 "count": <%= @counter%>
 }

and action:

def counter
 @counter //here I need to change variable
 respond_to do |format|
 format.jsonr do
  render :json 
   end
 end
end

and I’m taking this varibale using jQuery:

$.getJSON('http://127.0.0.1:3000/counter.json', function(data) {
    alert(data.count);//alert just for testing
})

EDIT: Suggested code:

     var counter = 0
     $(document).ready(function(){
var myCounter = new flipCounter('counter', {value:counter});
$.getJSON('http://127.0.0.1:3000/counter.json', function(data) {
 myCounter.setValue(data.count);
})
});  

   setInterval(function() {
    $.getJSON('http://127.0.0.1:3000/counter.json', function(data) {
 myCounter.setValue(data.count);
   }, 1000);

and I get error:

 Uncaught SyntaxError: Unexpected end of input application.js:1

Maybe someone can suggest something ? Maybe other solution ?

  • 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-11T08:29:28+00:00Added an answer on June 11, 2026 at 8:29 am

    You do not need to actually “change the variable every second”. It’s much simpler than that:

    1. Pick a start time (or end time) and store the value somewhere
    2. At any time, take the current time
    3. Calculate the difference between the two

    Done. You can repeat this algorithm at any time and always get the current status of the timer.

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

Sidebar

Related Questions

I have some complicated, problem to be solved. Now I need to write such
I have such problem: I'm using rails, devise gem and jQuery validation plugin. I
So, i have such problem: first time, then the <a> get clicked e.preventDefault() isn't
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have a problem such that i have zip files uploaded from forms and
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
The problem: I have a collection of people, I want to have a revise.html
I have a simple, real life problem I want to solve using an OO
This isn't a show-stopping programming problem as such, but perhaps more of a design

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.