Return data from PHP back to a javascript file?
<p>I have a comments section on my websites that uses jQuery to animate comments in without reloading the page, as well as deleting comments. </p>

<p>Right now, I have it so when you write a comment, it sends it to a external JS, then to a php file where it processes. If it was successful, it will append the comment into the comment section. My delete action: jQuery deletes my the comment ID in the mysql database. </p>

<p>So my issue is I want to add a delete button via jQuery and somehow call back to the javascript file and tell it the id so the delete button knows the ID to put in the form so the delete file knows what to delete?</p>

<p>Here's my <code>add_comment</code> script:</p>

<pre><code>$(function() {

$(".commentbutton").click(function() {

$.ajax({
  type: "POST",
  url: "http://myflashpics.com/process_addcomment.php",
  data: $("#commentform").serialize(),
  success: function() {

    var theComment = $("#commentsss").val();
    var theUserId = $("#user_id_two").val();
    var thePhotoId = $("#photo_id").val();
    var theProfilePicture = $("#user_profile_picture").val();
    var theUsername = $("#user_username").val();

    // Get new HTML data
    var html = "&lt;div class='comment_odd'&gt;&lt;img src='" + theProfilePicture + "' class='comment_thumbnail'/&gt;&lt;div class='comment_username'&gt;" + theUsername + "&lt;/div&gt;&lt;div class='comment_text'&gt;" + theComment + "&lt;/div&gt;&lt;/div&gt;";

    // Append, then fade in
    $(html).hide().appendTo(thecommentsdisplay).fadeIn(500);

  }
 });
return false;
});
});
</code></pre>

<p>Thanks in advance!<br>Coulton</p>

<p><strong>EDIT 1:</strong></p>

<p>Here's my comments form (just to clarify):</p>

<pre><code>user_id_two (the user's ID)
commentsss (comments field)
photo_id (the id of the photo being commented on)
user_profile_picture (profile to display on the user's profile picture in the banner)
user_username (username of the user commenting)
</code></pre>

<p>Here's also my delete button form: </p>

<pre><code>&lt;form method='post' action='' name='deleteform' id='deleteform'&gt;
&lt;input type='hidden' name='userid' value='&lt;?php echo "$userid_session"; ?&gt;' /&gt;
&lt;input type='hidden' name='userpass' value='&lt;?php echo "$password_session"; ?&gt;' /&gt;
&lt;input type='hidden' name='pictureid' id='pictureid' value='&lt;?php echo "$picture_id"; ?&gt;' /&gt;
&lt;input type='hidden' name='profilepictureid' id='profilepictureid' value='&lt;?php echo "$user_profile_picture_id"; ?&gt;' /&gt;
&lt;/form&gt;
</code></pre>

<p>And lastly my DELETE COMMENT jQuery:</p>

<pre><code>$(function() {

$(".commentdeletebutton").click(function() {

 var className = $(this).attr('class');  
 var theID = className.replace(/delete_button commentdeletebutton delete_(\d+)/, "$1");
 commentDone = "#comment_" + theID;
 formDone = "#commentdeleteform_" + theID;

 $.ajax({
  type: "POST",
  url: "http://myflashpics.com/process_deletecomment.php",
  data: $(formDone).serialize(),
  success: function() {

    $(commentDone).hide();

  }
 });
return false;
});
});
</code></pre>
