Ajax Kills The script

function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
    remainingSeconds = "0" + remainingSeconds; 
}
//store seconds to cookie
setCookie("my_cookie",seconds,1); //here 5 is expiry days

document.getElementById('countdown').innerHTML = minutes + ":" +    remainingSeconds;
if (seconds == 0) {
	clearInterval(countdownTimer);

//This makes my countdown stop working, shows "00:00" like it already finished it.
	$.ajax('includes/uhp.php', {
        success: function(response) {
           $('#countdown').html(response);
        }
    });


	setCookie('my_cookie', '', -1);

} else {    
    seconds--;
}

}

at this point your countdown should have stopped already.

No, I mean, it doesnt go, I made that it would erase the cookies whenever it finishes and it would restart ant go again on refresh. It works without the ajax part, it goes from begining to 00:00, but when I add the ajax part, it says 00:00 always.

can you post a live page? because your code and what you describe don’t go together.

Now the timer goes I think I needed to delete cokies or sm, but it doesnt load the php part.

That depends on what the PHP part is supposed to do.

Have a look.

<script type="text/javascript">
function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) 
  {
  var c = ca[i].trim();
  if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
return "";
}

//check existing cookie
cook=getCookie("my_cookie");

if(cook==""){
   //cookie not found, so set seconds=60
   var seconds = 60;
}else{
     seconds = cook;
     console.log(cook);
}

function secondPassed() {
    var minutes = Math.round((seconds - 30)/60);
    var remainingSeconds = seconds % 60;
    if (remainingSeconds < 10) {
        remainingSeconds = "0" + remainingSeconds; 
    }
    //store seconds to cookie
    setCookie("my_cookie",seconds,1); //here 5 is expiry days

document.getElementById('countdown').innerHTML = minutes + ":" +    remainingSeconds;
if (seconds == 0) {
	clearInterval(countdownTimer);
	$.ajax('includes/uhp.php', {
        success: function(response) {
           // the response (output) from the script will be added to div#countdown
           $('#countdown').html(response);
        }
    });
	setCookie('my_cookie', '', -1);

} else {    
    seconds--;
}
}

var countdownTimer = setInterval(secondPassed, 1000);
</script>

<span id="countdown" class="timer"></span>
<div id="countdown" class="timer"></div>

and the uhp php

    <?php
include_once 'db_connect.php';
include_once 'functions.php';
include_once '../system/study.php';
 
sec_session_start();

	if ($stmt = $mysqli->prepare("UPDATE members SET svcc = svcc+1 WHERE id = ? LIMIT 1")) {
		$user_id = $_SESSION['user_id'];
		$stmt->bind_param('i', $user_id);
                // check if the query did execute and that it affected a row
		if ($stmt->execute() && $mysqli->affected_rows > 0) {
			header("Location: ../test.php");
			exit;
		}
	}
	return false;

The php part does what it supposed to do when u launch it seperetly, but it doesnt work with that.

you mean it doesn’t update the DB?

Yeh it doesnt update the dbr, I mean it works when I use uhp.php dirrectly, but when the timer hits 00 it doesnt update db/ work.

you’ll need to check if your session propagates properly. that’s the only thing I can imagine right now.

How could I do that? Should I try adding the session begining on the top of the main php file and just include the script of the uhp? I guess that should work, since it gets the script but it play is in third party I guess.