Jquery,ajax和加载问题

时间:2011-09-16 11:05:18

标签: php jquery

这是HTML部分:

div id="messages">
   <div class="messages">


<?php if(isset ($unread)) { ?>
   <p>You have <?php echo $unread?> unread messages.</p>
    <?php } ?>

<?php if(isset ($messages)) { ?>
        <?php foreach ($messages as $msg){ ?>
      <div class="col_3">             
<?php     
      if($msg['read'] == 0){ echo 'Status of message: Unreaded';}
      elseif($msg['read'] == 1){echo 'Status of message: Readed';}
     echo "<p>Message from: $msg[name]</p>";
     echo "<p>Sender email: $msg[email]</p>";        
     echo "<p>Message: <br />$msg[message]</p>"; ?>
     <a href="#" class="delete" id="<?php echo $msg['id'] ?>">Delete message</a>
      </div>
 <?php } ?>                
<?php } ?><!-------- end of if $message-------->
       </div><!------ end of div .messages--------->
   </div><!------ end of div #messages--------->

和JQ:

  $(".delete").click(function() {    
    var commentContainer = $(this).parent();
    var id = $(this).attr("id");            
    var string = 'id='+ id ;
    $.ajax({   
        url: "<?php echo site_url('messages/delete') ?>",
        type: "POST",
        data: string,
        cache: false,
        success: function(){
            commentContainer.slideUp('600', function() {$(this).remove();
                $('.messages').fadeOut('2000', function(){$(this).remove();
                    $('#messages').load("<?php echo site_url('messages/show') ?>");
                }); 
            });               
        }   
    });
    return false;
});

代码正在运行,但是当涉及到负载时,没有显示任何内容。我做了

load("<?php echo site_url('messages/show') ?>", function() {

警告('已执行加载。'); });

并且有一个警报,当我查看页面源时,我可以看到内容已被更改,但它没有显示。

1 个答案:

答案 0 :(得分:0)

当您查看通过AJAX加载的页面的源时,它将永远不会更新。您需要检查DOM以查看更改的内容。

原因是因为内容实际上并不在页面上,而是被动态添加到页面中。