So im making a “delete” button to my commentsystem..
I want to make it smart, so it should run a ajax call to remove the comment.
Now I have tried out myself, this and have gotten this far:
<?php
echo "<a href='#' onclick='javascript:DoCommentWallRemove()' title='ta bort inlägg'> <span class='removeWallComment'></span> </a>";
?>
<script type="text/javascript">
function DoCommentWallRemove(){
var wrapperId = '#profileWall';
$.ajax({
type: "POST",
url: "misc/removeWallComment.php",
data: {
value: 'y',
commentwallid : "<?php echo $displayWall['id']; ?>",
BuID : "<?php echo $v['id']; ?>",
uID : "<?php echo $showU['id']; ?>"
},
success: function(msg){
alert(msg);
}
});
}
</script>
Now as my comments shows in a while(), I have placed the JS function is right under the link, so it should grab the actual comment id, but instead it gives the same ID to every comment.
But when i do a normal php <?php echo $displayWall['id']; ?> it shows different comment ids like it should do in the javascript.
I would suggest a similar solution to GuidoH, but with a few minor changes.
PHP Code for the Comment Thread:
This will render as:
In the Javascript for the page holding the Comment thread:
In the misc/removeWallComment.php file:
NOTE:
This advice is based on the assumption he BuID and uID variables are the same for any delete action performed by the user from the same page.
Edited:
Updated to provide Graceful Degradation in the event that the user does not allow Javascript to run, and to extract a number of variables from the HTML FORM, (rather than have to code them in twice).