I try to pass this value to my php code, but I do not know how to do it. post method does not work. (I do not know why).
<script>
var val = localStorage.getItem('sumalist');
$.ajax({
type: "POST",
url: "index.php",
data: {value: val},
success: function () {
console.log(val);
}
});
</script>
and in my php code, value is not set.
if (isset($_POST["value"])) {
echo "Yes, value is set";
$value = $_POST["value"];
}else{
echo "N0, value is not set";
}
PS: My php code is in the same file in js code.
index.phpis returning a HTML document with that script tag included, you won't notice whether the value is set or not. The return value of your ajax request is never used... Please specify what you wan't to achieve after sending the ajax request.var val = localStorage.getItem('sumalist');returns a float. I would like this value send to sql query.:$value = $_POST["value"]; if ($polaczenie->query("INSERT INTO zamowienia VALUES ('$value')")) ...