I need to pass a data of localstorage
to a variable php , and I store the data in a script on the same page but I get null
to php , I do not know what I'm doing wrong or what I'm missing, I attach my code, thanks in advance for the help.
I capture the data from a form with a select, in an echo of php with the function save (), as I said I get to the localstorage and I even see the value in the local function () the local function is executed at load the page and take the data from the localstorage and send it to php via ajax (or that it was supposed to do), but it arrives null to php.
<script type="text/javascript">
function guardar () {
var count = document.getElementById('count').value;
localStorage.setItem('count', count);
var con = localStorage.getItem('count');
saved = parseInt(con);
console.log('count');
alert(saved);
}
</script>
<script type="text/javascript">
function local(){
var con = localStorage.getItem('count');
var saved = parseInt(con);
alert(saved);
$.ajax({
type: "POST",
url: "index.php",
data: {data: saved},
success: function(data) {
$('#output').html(data);
alert(saved);
}
});
};
</script>
<?php
$saved = $_POST['data'];
?>