Ajax + $_Session

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
ossy
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Oct 11, 2020 7:53 am

Wed Nov 25, 2020 12:35 pm

Hi there

I'm trying to send from Ajax some variables to PHP Session variable.
Getting an error, but able to find what is wrong.

Here is my javascript:
...
<script>
function GetLine(el){
$.ajax({
url: 'put_session.php',
method: 'POST',
data:{
'toto': '0',
'tata': '0',
'titi': el.cells[0].innerHTML
},
success: function(response) {
console.log('Ok status: ' + response);
},
error: function(xhr, status, error){
var errorMessage = xhr.status + ': ' + xhr.statusText;
console.log('Error: ' + errorMessage );
}
});
window.location.href = 'newpage.php';
}
</script>

and here my php page to store session variable: (put_session.php)

<?php
session_start();
if (isset($_POST['toto'])) {
$_SESSION['toto'] = $_POST['toto'];
}
if (isset($_POST['tata'])) {
$_SESSION['tata'] = $_POST['tata'];
} if (isset($_POST['titi'])) {
$_SESSION['titi'] = $_POST['titi'];
}
echo "success";
?>

I get this error message: Error: 0: error

Thanks in advance for any help.


Ossy
Post Reply