0

In a script I use AJAX to request data from a script. The returned data is returned in JSON format. The script returns seconds and I'm searching for an easy way to generate a countdown showing minutes and seconds generated by the returned value.

For example if the script returns 90 I would need a countdown ticking each second showing: 1:30

Using the jQuery docs I only found this script, but it will require minutes and seconds to start the countdown from. Script called via AJAX only returns seconds.

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
peke_peke
  • 441
  • 7
  • 21
  • Possible duplicate of [jQuery countdown timer](http://stackoverflow.com/questions/3785029/jquery-countdown-timer) – Takoyaro Jun 13 '16 at 20:11

1 Answers1

2

To convert number of seconds to minutes:seconds, you could use the following, where totalSeconds is the return from your AJAX request.

mins = Math.floor(totalSeconds / 60);
secs = totalSeconds % 60;

Then use the script you linked above.

Chris Wissmach
  • 505
  • 4
  • 11