How to receive SESSION value in real time with AJAX?

Asked

Viewed 27 times

2

Well, what I have achieved so far is to make the user click on any of the pagination buttons (1, 2, 3...) PHP save a SESSION with the corresponding page number.

Follows the code:

<!-- BOTÃO COM O NÚMERO DA PÁGINA -->    
<button onclick="mudaVar(<?php echo $i; ?>);">
    <?php echo $i; ?>
</button>

<!-- FUNÇÃO PARA GUARDAR SESSION PG -->
function mudaVar(valor) {
    $.ajax({
        url:'sessions.php?valor='+valor
    });
}

// GUARDA SESSION PG
if(isset($_GET['valor'])){
    $_SESSION['pg'] = $_GET['valor'];
}

So far so good, only the problem is that SESSION is not changed at that time, only when I update the page.

How to fix this?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.