用动态php内容覆盖正确的方法? [英] overlay with dynamic php content the right way?

查看:104
本文介绍了用动态php内容覆盖正确的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将点击功能中的动态内容显示到我制作的灯箱中时遇到一些问题. 列出了三个文件:

I am having a few problems displaying dynamic content from a click function and into sort of a light box I made. there is three files as listed:

index.php

index.php

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

In the index I have a foreach with all the records from the table and the record 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.

In the jQuery file I'm getting the id of the element I'm clicking. now I want to pass it into the article file to fetch the data with the clicked id. I'm using the function .load to load the file into the lightbox but I can't get the 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文件已在请求之前加载.

Here, I want to receive the article_id from jquery with $.post but I'm getting an undefined index. I'm thinking it's because the article.php file has been loaded before the request.

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

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

I hope sombody can help me, or tell me the right way to do it.

推荐答案

尝试一下:

$('.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);
    });
});

这篇关于用动态php内容覆盖正确的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆