OiO.lk Blog PHP How do I pass a data stored in a local storage in JavaScript file to a PHP file to be processed
PHP

How do I pass a data stored in a local storage in JavaScript file to a PHP file to be processed


I tried using ajax method but I don’t really understand ajax All I want is to get the data from the local storage in my JavaScript file to my PHP file so that I can compare the value to what the value from my database is giving me please help me

javascript code

let pid = localStorage.getItem("pid");
$.ajax({
  type: 'POST',
  url: 'addcomments.php',
  data: pid,
  
});

php code

<?php
if (isset($_POST["com-btn"])) {
$mess = $_POST["comments"];
$postid = $_POST['pid'];
echo "Received PID: $postid";
}
?>



You need to sign in to view this answers

Exit mobile version