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");

if (ajax.readyState==4 && ajax.status==200)
}"POST","update_likes.php", false);
ajax.send("image_id=" + id);


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" />
        <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="//;href='.$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>


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.

2011/09/14 18:17
  • onclick
  • php
  • ajax
  • 点赞
  • 收藏
  • 回答