hi guys, i have a (searchresult.php) in the (index.php), which I trying use ajax post from (searchresult.php) to pass and ID back to (index.php), however my <?php echo $_POST["dataid"]; ?> keep showing empty result, I also check my console log it show result send through but why my <?php echo $_POST["dataid"]; ?> keep showing empty result. Can anybody pls help I have been stuck almost 2 months. Appericate that anybody can help me. thank you.

searchresult.php

 <a onClick="openoverlay(<?php echo $data["ID"]?>)"><?php echo $data["ID"]?><a> 

index.php

 function openoverlay(dataid) {

            var myData = 'dataid='+dataid;

            $.ajax({
            url: "index.php",
            type:"POST",
            dataType:"text",
            data:myData, //Pass your varibale in data
            success:function(data){
            console.log(data);
            alert(dataid); //you get return value in this varibale, us it anywhere
            }
            });

            document.getElementById("myNav").style.display = "block";

    }  

    function closeoverlay() {
              document.getElementById("myNav").style.display = "none";
    }

   <div id="myNav" class="overlay">

                      <a href="javascript:void(0)" class="closebtn" onclick="closeoverlay()">&times;</a>
                      <div class="overlay-content">

                        <div style=" background:#F00; width:100px; height:100px; color:#FFF; border-color:#ff0; border-width:1px; border-style:solid;"><?php echo $_POST["dataid"]; ?> 
                        </div>

                        <a href="#">About </a>
                        <a href="#">Services</a>
                        <a href="#">Clients</a>
                        <a href="#">Contact</a>
                      </div>
          </div>

column2.png

consolelog.png

overlaypic.png

It looks like you're trying to mix JS with PHP here. You need to add some code to the ajax success function to do something with the result. From the code you posted, I'm not sure you're actually getting the result you want. But if you are, this code should help you out.

In the index.php file, add an id to the div that contains <?php echo $_POST["dataid"];?>. Let's say you make the id id="resultDiv".

Then in the ajax success function, add this line $("#resultDIV").html(dataid). This will change the contents of the div to the ajax results.