JQuery Ajax add data into php session
Permalink
How to add javascript data into php session
$.ajax({
type: 'POST',
url: '<?php echo $view->getThemePath()?>/elements/s_session.php ?>',
data: {'value': out}
})
.done(function(data){
alert(data);
window.location.href = 'ord_d';
}).error(function(er){
alert('error');
});
s_session.php
<?php
session_start();
if(isset($_POST)){
if (isset($_POST['value'])) {
$value = $_POST['value'];
$_SESSION['pdtmsr-qrcode'] = $value;
echo $_SESSION['pdtmsr-qrcode'];
}
}
?>
$.ajax({
type: 'POST',
url: '<?php echo $view->getThemePath()?>/elements/s_session.php ?>',
data: {'value': out}
})
.done(function(data){
alert(data);
window.location.href = 'ord_d';
}).error(function(er){
alert('error');
});
s_session.php
<?php
session_start();
if(isset($_POST)){
if (isset($_POST['value'])) {
$value = $_POST['value'];
$_SESSION['pdtmsr-qrcode'] = $value;
echo $_SESSION['pdtmsr-qrcode'];
}
}
?>
For block controllers, you can shortcut the route creation by using a block action.
In the documentation, the topics to read up on are routes, on_start event handlers, block actions and ajax.