Ajax帖子为空

时间:2019-11-23 08:54:31

标签: php ajax

我在(index.php)中有一个(searchresult.php),我试图使用来自(searchresult.php)的ajax帖子将ID传递回(index.php),但是$ _POST [“ dataid “]继续显示空结果,但控制台日志显示结果已发送出去。有人可以帮助我吗,我被困了将近2个月。我感谢任何人都可以帮助我。谢谢。

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>

enter image description here

enter image description here

enter image description here

0 个答案:

没有答案