This function will get the value from the input and sent data with ajax to another php file. But I cannot get the result back from php file when I echo and store in ajax success function result.
<script> $(document).ready(function(){ $('.edit-button').click(function(){ let clickpostid = $(this).prev().val(); console.log(clickpostid);// I can see the input value $.ajax({ url: "post/edit.php", method: "POST", data: { clickpostid }, success: function(result){ alert(result); //When I alert the result is blank not null or undefied. } }) }); }) </script>
Below code will be in another file such as edit.php.
<?php include('../db.php'); if(isset($POST_['clickpostid'])){ $id = $POST_['clickpostid']; echo $id; } ?>
Advertisement
Answer
Your edit.php should be this:
You should use $_POST
instead of $POST_
<?php include('../db.php'); if(isset($_POST['clickpostid'])){ $id = $_POST['clickpostid']; echo $id; } ?>