Link to home
Start Free TrialLog in
Avatar of designaire
designaireFlag for United States of America

asked on

send to Ajax when timer ends

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

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of designaire

ASKER

I think it works!! I have to test it a bit more.
I can't thak you enough