Solved

send to Ajax when timer ends

Posted on 2014-12-03
3
151 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

770 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