0

我有这样的观点,从数据库中获取所有帖子:-

<ol class="timeline2 clear">
  <li class="spine">

  </li>

  <?php 
  $counter=0;
  foreach ($response as $row) { 
  if($counter % 2 == 0){$class= "left";} else $class="right";
  ?>

   <li class="<?=$class ?>">
    <i class="pointer"></i>
    <div class="unit">

      <!-- Story -->
      <div class="storyUnit">
        <div class="imageUnit">
         <? if (empty($row->pic)) { ?>
          <a href="#"><img width="32" height="32" alt="" src="images/nopic.png"></a>
          <? } else  { ?>
          <a href="#"><img width="32" height="32" alt="" src="uploads/<?php echo $row->pic; ?>"></a>
          <div id="delpost" style="float:left"><a href="#" id="deletepost" onClick="delete_post('<?=$row->ev_id;?>');">X</a></div>
          <? } ?>
          <div class="imageUnit-content">
            <h4><a href="./home/myaccount/<?php echo $row->id; ?>"><?php echo $row->fullname; ?></a></h4>
            <p><?php echo $row->ev_date ?></p>
          </div>

        </div>

        <p> <?php echo $row->ev_text; ?><br />
        <? if (!empty($row->ev_pic)) { ?>
        <img src="uploads/<?php echo $row->ev_pic ?>" width="250" height="250"</p>
        <? } ?></p>

      </div>
      <!-- / Story -->

      <!-- Units -->
      <ol class="storyActions">


      </ol>
      <!-- / Units -->

    </div>
  </li>

   <?php $counter++; } ?>
   <div class="clear"></div>
</ol>

然后我不会删除任何帖子,所以我点击:-

<div id="delpost" style="float:left"><a href="#" id="deletepost" onClick="delete_post('<?=$row->ev_id;?>');">X</a></div>

该函数delete_post是调用控制器删除帖子的jquery:-

function delete_post( ev_id )
{   
    var message_confirm =confirm("are you sure?");
    if (message_confirm==true)
       {
    $.ajax({
        url: "home/deletePostInProfile",
        type: "POST",
        data: {ev_id : ev_id },
        dataType: "json",
        success: function(data)
        {
            if(data.process == "ok")
            {
                $("#post_row"+ev_id).remove();      
            }

        }  
    });
       }
       }

所以当调用函数并删除帖子时,页面刷新并转到主页。

控制器是:-

public function deletePostInProfile() {

$this->load->model('blog');
$ev_id=intval($_POST['ev_id']);

$result = $this->blog->deletePost($ev_id);

}

为什么刷新页面并转到主页?

4

2 回答 2

1

如果您想在删除帖子后重新加载页面,请执行以下操作:

function delete_post( ev_id )
{
    var message_confirm =confirm("are you sure?");
    if (message_confirm==true)
    {
        $.ajax({
            url: "home/deletePostInProfile",
            type: "POST",
            data: {ev_id : ev_id },
            dataType: "json",
            success: function(data)
            {
                if(data.process == "ok")
                {
                    $("#post_row"+ev_id).remove();
                    window.location.href = "http://your.url";
                }

            }
        });
    }
}
于 2013-08-21T07:22:51.943 回答
0

您可以使用 window.location.reload() 成功删除后重新加载页面

function delete_post( ev_id )
{   
    var message_confirm =confirm("are you sure?");
    if (message_confirm==true)
       {
    $.ajax({
        url: "home/deletePostInProfile",
        type: "POST",
        data: {ev_id : ev_id },
        dataType: "json",
        success: function(data)
        {
            if(data.process == "ok")
            {
                $("#post_row"+ev_id).remove(); 
                window.location.reload();     
            }

        }  
    });
       }
       }
于 2013-08-30T11:50:09.647 回答