Solved

send to Ajax when timer ends

Posted on 2014-12-03
3
148 Views
Last Modified: 2014-12-03
This timer works fine but I need to send the results to Ajax when it is done. This seems to work in chrome unless the cache is cleared or it plays the first few times. I'm wondering if there is another way to send it to Ajax when it is done. I don't know how to tell when it's done. Somebody helped me with this code and I'm very new at code.

http://squareonemeditation.com/webapp/meditatetest.php


 
function drawTimer(percent){
             
             $('div.timer').html('<div id="slice"'+(percent > 50?' class="gt50"':'')+'><div class="pie"></div>'+(percent > 50?'<div class="pie fill"></div>':'')+'</div>');
             var deg = 360/100*percent;
             $('#slice .pie').css({
                   '-moz-transform':'rotate('+deg+'deg)',
                   '-webkit-transform':'rotate('+deg+'deg)',
                   '-o-transform':'rotate('+deg+'deg)',
                   'transform':'rotate('+deg+'deg)'
             });
             $('.percent').html(Math.round(percent)+'%');
       }
       
       $(stopWatch = function() { 
       
             if(percent >=100){
                   drawTimer(100);
                   clearInterval(timer);
                                           
                               $.ajax({
                                     url: "postmeditate.php",
                                     type : "POST",
                                     data: { length: length, userid: userid},
                               })
                               .success(function (response){
                                     location.href = "tracking.php";                                          
                               })
                               .error(function (e){
                               });
                   
             }else{
                   percent += (timerSeconds/minutes)
                   drawTimer(percent);
                   counter++;
             }

 });

Open in new window

0
Comment
Question by:designaire
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40478649
replace line 20 :
 $.ajax({

Open in new window

by :
 $.ajax({
      async:false,

Open in new window

0
 

Author Comment

by:designaire
ID: 40478689
I think it works!! I have to test it a bit more.
0
 

Author Closing Comment

by:designaire
ID: 40478753
I can't thak you enough
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now