Let's break it down, here's the code I'm working with. It's meant to update the "like" column in my "comments" table. The issue arises when trying to submit the result in JavaScript.
There's a SPAN containing a link to submit:
<span id="like<?=$i?>"><a href="javascript:void()" onClick="likeComment(<?=$row[commentid]?>, <?=$i?>)" />Like</a> (<?=$row[like]?>)</span>
The comment ID is represented by commentid and $i signifies the comment number for updating the correct SPAN tag upon submission of the +Like action.
Next comes the AJAX function that posts 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>
The intention is to send the comment ID and SPAN ID, so the PHP response would be:
<span id="like<?=$number?>"><font color="#009900">You like this</font> (<?=$row[like] + 1?>)</span>
(I omitted the PHP part as the issue doesn't lie there.)
I can't figure out why it's not functioning. It works fine with just one ID, which leads me to suspect either
xmlhttp.open("GET","like_game.php?id="+id"&no="+no,true);
or
document.getElementById("like"+no).innerHTML=xmlhttp.responseText;
In essence, the goal is to submit comment ID 60, for instance, located in SPAN ID'd 5, so on submission, it should return in the right ID.
Any insights are welcome, as I'm at a loss here.