Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中通过jquery删除后刷新页面_Php - Fatal编程技术网

Php 在codeigniter中通过jquery删除后刷新页面

Php 在codeigniter中通过jquery删除后刷新页面,php,Php,我有一个从数据库获取所有帖子的视图,如下所示:- <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="

我有一个从数据库获取所有帖子的视图,如下所示:-

<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>
所以当调用函数并删除帖子时,页面会刷新并转到主页

控制器是:-

public function deletePostInProfile() {

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

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


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

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

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";
                }

            }
        });
    }
}

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


你需要更清楚地解释这个问题以及你想要实现的目标。如果你删除了一行,页面会重新加载吗?要停止此操作吗?请尝试在成功功能中发出一些警报,以查看重新定位发生的位置。因为现在,我不知道在哪里会发生这种情况。我会将alert
success:function(data){alert(“”);if(data.process==“ok”){$(“#post_row”+ev_id)。remove();}}
它不会显示任何警报,所以下次打开列表时,问题所在的位置会被删除?我猜这是来自CI方法。我不太了解CI。试着通过这个方法去死,也就是说,给一个骰子(“HelloWorld”);在方法的第一行,然后一步一步地进行。或者,如果您有可能调试并执行此操作,则更容易。
public function deletePostInProfile() {

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

$result = $this->blog->deletePost($ev_id);
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";
                }

            }
        });
    }
}
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();     
            }

        }  
    });
       }
       }