This is actually happening in IE7 also. Is it possible that something
is hosed with my code? I'm more confident it's that than a broken
replaceWith() but I'd really like to know why it only works once, and
then I need a page refresh for that "ajax" effect.

- sf

On 9/24/07, Steve Finkelstein <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> So I have a simple script which essentially uses .replaceWith() to
> replace the containing elements HTML with a success callback. This
> works fine the first time I invoke a function which calls
> .replaceWith() in the success call back, but any subsequent calls
> leaves the DOM unmodified.
>
> Here's an example screenshot of what my page looks like upon a random page 
> load.
>
> http://catalyst.httpd.org/tmp/1.png
>
> Ok so I have 4 notes. Let's delete one:
>
> http://catalyst.httpd.org/tmp/2.png
>
> Perfect, it's gone:
>
> http://catalyst.httpd.org/tmp/3.png
>
> Here's where the problem occurs... Let's delete another
>
> http://catalyst.httpd.org/tmp/4.png
>
> Hmmm, it didn't disappear from the DOM this time:
>
> http://catalyst.httpd.org/tmp/5.png
>
> The OB/GYN note is still there as rendered by the browser, however the
> server-side script surely wiped it:
>
> mysql> select id,name from ms_notes where id="CN";
> Empty set (0.00 sec)
>
> Here's what my code looks like to remove the note:
>
> function removeNote(id,name) {
>         if(confirm("Are you sure you wish to delete: "+name+"?")) {
>                 // ajax code here to remove note.
>                 $.ajax({
>                   url: "/dbserver.php",
>                   type: "POST",
>                   data: "delete="+id,
>                   cache: false,
>                   success: function(html) {
>                         $("#alpha_notes").empty();
>                     $("#alpha_notes").replaceWith(html);
>                   }
>                 });
>         }
> }
>
> Very important thing to factor in, is if I do a hard refresh on the
> page, here are the results... a missing OB/GYN note, which is the way
> it should be:
>
> http://catalyst.httpd.org/tmp/6.png
>
> Any idea folks? Would really appreciate any help. Firebug also shows
> that in its response to my POST call that the notes are not there in
> its table rendering. My server-side code looks like this:
>
> if($_POST['delete']) {
>         global $db_alpha, $link;
>         $alpha_note_set = array();
>         $db = mysql_select_db($db_alpha, $link);
>     if(!$db) {
>         die("Can't connect to alpha, please contact steve.");
>     }
>
>     $sql = "DELETE from ms_notes
>                         WHERE ID='".$_POST['delete']
>                 ."' LIMIT 1";
>         $result='';
>     $result = mysql_query("$sql");
>         if(!$result) { die("Something is broken... "); }
>
>         $sql = "SELECT NAME,ID from ms_notes";
>     $alpha_result_set = @mysql_query("$sql");
>     $row='';
>     if(mysql_num_rows($alpha_result_set)==0) { $html = "There are zero
> notes left to process in Alpha's database"; echo $html; exit; }
>         while($row = @mysql_fetch_array($alpha_result_set, MYSQL_ASSOC)) {
> $alpha_note_set[] = $row; }
>         $html='';
>         $html = '<table>';
>         $html .= '<tr>';
>                 // count here basically just keeps track of a
>                 // neatly aligned table
>                 $count=0;
>             foreach($alpha_note_set as $note) {
>                 $html .= "<td><a href=\"javascript:void(0);\"
> onclick=\"removeNote('".$note[ID]."','".$note[NAME]."')\">delete</a>&nbsp;&nbsp;$note[NAME]</td>";
>                 $count++;
>                 if(($count % 2 == 0)) {
>                         $html .= "</tr><tr>";
>                 }
>                 }
>         $html .= '</tr></table>';
>
>         // send this sucker back to the view.
>         echo $html;
> }
>
> Thanks all.
>
> - sf
>

Reply via email to