Solved

send to Ajax when timer ends

Posted on 2014-12-03
3
155 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
[X]
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
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

729 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