以正确的方式覆盖动态 php 内容?

overlay with dynamic php content the right way?

我在显示来自点击功能的动态内容和我制作的某种灯箱时遇到了一些问题。 列出了三个文件:

index.php

在索引中,我有一个 foreach,其中包含 table 中的所有记录和记录 ID。

<?php
   foreach($id as $id){
?>
    <div class="event">
       <a class="id" href="javascript:void(0)" id="<?php echo $id;?>">click to see more</a>
    </div>
<?php
   }
?>

jquery 文件

在 jQuery 文件中,我获取了我正在单击的元素的 ID。现在我想将它传递到文章文件中以获取具有点击 ID 的数据。 我正在使用 .load 函数将文件加载到灯箱中,但我无法获取 ID。

$('.id').click(function(){
    var article_id = $(this).prop('id');
    $.post("article.php", {"article_id": event_id});
    $('.article').load("article.php");
});

文章文件

在这里,我想使用 $.post 从 jquery 接收 article_id,但我得到了一个未定义的索引。 我认为这是因为 article.php 文件在请求之前已经加载。

<div class="article">
   <!-- here I want to get the $_POST['article_id']-->
</div>

希望有人能帮助我,或者告诉我正确的方法。

试试这个代码:

<?php

$idlist = array(1,2,3,4);
   foreach($idlist as $id){
?>
    <div class="event">
       <a class="id"  href="javascript:void(0)" id="<?php echo $id;?>">click to see more</a>
    </div>
<?php
   }
?>



<div class="article">

</div>

<script language="javascript">
       $(function(){
           $('.id').click(function(){
                $(".article").load("article.php", {id: $(this).attr('id')});
           })
        })
</script>

试试这个:

$('.id').click(function(){
    var article_id = $(this).prop('id');
    // send article_id and get the return content in data
    $.post("article.php", {article_id : article_id}, function(data){
        $('.article').html(data);
    });
});