Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

send to Ajax when timer ends

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS issue in Nested Master Pages 9 26
DataTables + iCheck + pagination Issue 2 44
Make options hidden and show just option that is on 1 28
Ajax and PHP 4 29
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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