weixin_33739523 2011-09-14 18:17 采纳率: 0%
浏览 23

PHP和AJAX onclick问题

I need some help to get this to work. It works, but i have to click at the side of the like button. I want it to register the click when the iframe is clicked. I tried setting the onclick in the iframe too, but that didn't work either.

This is my script in the top of the page:

<script type="text/javascript">
function updateLikes(id) {
var ajax;

// Code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
    ajax=new XMLHttpRequest();
} else { // code for IE6, IE5
    ajax=new ActiveXObject("Microsoft.XMLHTTP");
}

ajax.onreadystatechange=function()
{
if (ajax.readyState==4 && ajax.status==200)
{
document.getElementById("images0").innerHTML=ajax.responseText;
}
}

ajax.open("POST","update_likes.php", false);
ajax.send("image_id=" + id);

}
</script>

Then there is what im echo'ing out:

        echo '
        <div align="center" class="images" id="images'.$i.'">
        <a class="image" border="0" href="p.php?id='.$row['id'].'">
        <img class="img" src="'.$row['path'].'" alt="image" />
        </a>
        <div class="meta" style="padding-bottom:5px;">Lastet opp av <div style="color:#47a09f; display:inline;"><a href="user.php?user='.$row['uploader'].'" style="color:#47a09f;">'.$row['uploader'].'</a></div></div>
        <div id="likebutton" class="faceLike" align="center" onClick="updateLikes(' . "'" . $row['id'] . "'" . ');"><iframe src="//www.facebook.com/plugins/like.php?app_id=144501772249167&amp;href=http://www.puffys.net/p.php?id='.$row['id'].'&amp;send=true&amp;layout=button_count&amp;width=0&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=tahoma&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe></div>

        </div>
        ';

My problem is the facebook button. When i click it, i want it to register the click with onclick so it's inserted to my database. But that does not happen. Only if i click at the side of the like button.

Thx in advance.

  • 写回答

1条回答 默认 最新

  • weixin_33695082 2011-09-14 18:24
    关注

    You won't be able to capture the click event of the DIV, as the document ONCLICK event from the IFRAME precedes it.

    Also, you won't be able to capture the click event of the IFRAME, as it is overriden by the destination page.

    You need to use the Facebook API, as described here: Facebook "Like" button callback

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办