This question already has an answer here:
I need to change the value of a PHP variable to JavaScript code.
The value of the PHP variable has to be something out of (JavaScript) localStorage.
So it is something like this.
$variable = localStorage.anameofalocalstorage; //The localstorage part is js
How can I do this?
</div>
This is an example code using jquery for the ajax call.
<?php
$variable_that_should_be_set=isset($_GET['shoudBeSet'])?$_GET['shoudBeSet']:'notSet';
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div id="div1"><?php echo $variable_that_should_be_set;?></div>
<a href="#" id="button">Click here to Set</a>
<script>
$("#button").click( function () {
$.get("?shouldBeSet=this_is_set")
})
</script>
</body>
</html>