views:

37

answers:

1

Alright so pretty basic, here are the pieces of code I have, basically it's supposed to updated my table "comments" on the "like" column. My problem is situated in the javascript while trying to submit the result.

SPAN which contains a link to submit:

<span id="like<?=$i?>"><a href="javascript:void()" onClick="likeComment(<?=$row[commentid]?>, <?=$i?>)" />Like</a> (<?=$row[like]?>)</span>

Basically commentid is the actual comment ID, and $i is the comment # (so when I submit the +Like it will actually update the right SPAN tag.

After that, I have my AJAX which will post it to my PHP file:

<script type="text/javascript">
function likeComment(id, no)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("like"+no).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);
xmlhttp.send();
}
</script>

Basically it is supposed to submit the comment ID and the comment SPAN ID, so then my PHP file will return

<span id="like<?=$number?>"><font color="#009900">You like this</font> (<?=$row[like] + 1?>)</span>

(I didnt include the PHP, my issue isnt stiuated in there.

I don't know what the problem is, but it wont work. When I do it with just one ID, it does work so in my opinion, there is a problem with either

 xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);

or

document.getElementById("like"+no).innerHTML=xmlhttp.responseText;

So bascially it is supposed to submit comment ID 60 for example, it is situated in the SPAN ID'd 5, so when it submits it, it should be supposed to return in the right ID.

Any help is appreciated, because I'm clueless here.

+5  A: 
xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);

should be like:

xmlhttp.open("GET","like_game.php?id="+id +"&no="+no,true);

I am thinking you are missing one "+" in the line above :)

Michael Mao
you don't know how much of a life savior you are! it now works perfectly. thank you alot michael! as simple as it look, but it took me alot of time to figure it out, with your help of course!
Alex Cane
@Alex Cane: You are welcome! This happens to me as well at times :) By the way, I reckon this is a good reason of having pair programming at work.
Michael Mao
Reminds me of this one: http://stackoverflow.com/questions/549693/js-file-not-being-executed/549696#549696
some