Question : Jquery Dialog Ajax problem

(This question is now a 1000 pointer.  I am posting it a 2nd time because it hasn't been answered and has fallen down the list and isn't getting any new attention so... answer it and then find the other one titled "jQuery Dialog Ajax PHP problem [PART 2]" and paste the same answer there too and you'll have 1000 points!)


I am using the dialog submit to trigger the ajax request and I am getting the new html back from the remote PHP script.  However, my new problem is that my jquery scripts no longer function on the new html that is returned.  If you use the link below, you will see that after you submit the new comment and the new html is returned, the dialog no longer appears when you click the "comment" link.  You can also see that my "remove buttons" no longer function the same.

I need to everything to function the same everytime the a new html is returned from the ajax request.  Thanks for the help.

http://www.pltproject.org/testing18/test_shit/dialog_ajax_test.php
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
<?php 
require_once('../Connections/PLT.php'); 

//setting these variables manually for test page purpose
$to = 'joshua';
$from = 'joshua'; 


mysql_select_db($database_PLT, $PLT); // Gets all wall posts
$query_wall_posts = "SELECT A1.user_id, A1.first_name, A1.last_name, A2.reply, A2.post_message, A2.timestamp, COALESCE(A2.reply_to_id, A2.post_id)reply_id  FROM users A1, wall_posts A2 WHERE A1.username = A2.from AND A2.to = 'joshua' ORDER BY reply_id DESC, timestamp";
$wall_posts = mysql_query($query_wall_posts, $PLT) or die(mysql_error());
$row_wall_posts = mysql_fetch_assoc($wall_posts);
$totalRows_wall_posts = mysql_num_rows($wall_posts);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../includes18/jQuery/css/plt-theme/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<link href="../main.css" rel="stylesheet" type="text/css" />
<script src="../includes18/jQuery/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../includes18/jQuery/js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
<script src="../scripts/wall_buttons.js" type="text/javascript"></script>
<script type="text/javascript">
var data_part1 = "";
$(function() {      
		$("#comment_dialog").dialog({
			autoOpen: false,
			height: 180,
			width: 560,
			modal: true
		});
		$(".faux_link").click(function() {
				$('#comment_dialog').dialog('open');
				data_part1 = $(this).attr('name');
		});
		$("#add_comment_button").click(function() {
					$("#comment_dialog").dialog('close');
					var query_string = data_part1 + $('#comment_input').val();
					$.ajax({
						url: "../scripts/comment_dialog.php",
						dataType: "html",
						data: query_string,
						success: function(data){
							$('#wall_post_cont').html(data);
						}
					});
		});
});
	</script>
	
    </head>
<body style="background-color:#FFF;">
    
<div id="desktop_right">
<div id="wall_post_cont">
   <?php if($totalRows_wall_posts > 0) { //show if recordest is not empty ?>
						<?php do { ?> 
                            <?php if ($row_wall_posts['reply'] == 'N') { //show if not reply ?>
                            <div class = "wall_post">
                                <div class = "poster_img">
                                </div>
                                <div class = "post">
                                    <a href="visitor.php?i=<?php echo $row_wall_posts['user_id']?>"><strong><?php echo $row_wall_posts['first_name'] . ' ' . $row_wall_posts['last_name']; ?></strong></a> <?php echo $row_wall_posts['post_message']; ?><br /><span style="line-height: 2.0; font-size:10px; "><?php echo date('F j, Y at g:ia', strtotime($row_wall_posts['timestamp'])); ?> | <span class="faux_link" name="<?php echo "reply_id=" . $row_wall_posts['reply_id'] . "&to=" . $to . "&from=" . $from . "&post_message="; ?>">Comment</span></span> 
                              	</div>
                                <div class="remove_button_cont">
                                 	<button style="float:right;">Remove</button>
                                </div>
                            </div>
                            <?php } // Show if not reply ?>
                            
                            <?php if ($row_wall_posts['reply'] == 'Y') { //show if reply ?>
                            <div class="reply_cont">
                                <div class="reply_top">
                                </div>
                                <div class="reply_img">
                                </div>
                                <div class="reply">
                                	 <a href="visitor.php?i=<?php echo $row_wall_posts['user_id']?>"><strong><?php echo $row_wall_posts['first_name'] . ' ' . $row_wall_posts['last_name']; ?></strong></a> <?php echo $row_wall_posts['post_message']; ?><br /><span style="line-height: 2.0;"><?php echo date('F j, Y at g:ia', strtotime($row_wall_posts['timestamp'])); ?> | <span class="faux_link" name="<?php echo "reply_id=" . $row_wall_posts['reply_id'] . "&to=" . $to . "&from=" . $from . "&post_message="; ?>">Comment</span><!-- I'm setting this name attr with my ajax data to be sent--></span> 
                                </div>
                            </div>
                            <?php } // Show if reply ?>
                        <?php } while ($row_wall_posts = mysql_fetch_assoc($wall_posts)); ?>
                    <?php } // Show if recordset is empty ?> 
                    </div>
                    </div>
                    
<div id="comment_dialog" title="Comment">
  	<textarea style="margin-top: 15px;" name="comment_input" rows="3" id="comment_input" ></textarea>
    <span style="float:right; margin-top:10px; font-size:12px">
        <input id="add_comment_button" class="input_button" name="submit" type="submit" value="Submit" />
    </span>
</div>
</body>
</html>

Answer : Jquery Dialog Ajax problem

Did you change the OTHER statement as well?
 $("#add_comment_button").click(function()

should be:
 $("#add_comment_button").live('click',function()
Random Solutions  
 
programming4us programming4us