dongzhuner6981 2018-10-15 11:38
浏览 48
已采纳

如何使用codeigniter中的onclick函数将id传递给控制器

This is my code. I want to pass Id to use in the controller for delete

<button onclick="Delete(<?php echo $article->id; ?>)">Delete</button>

And this is function through which the id is passed to the controller

<script type="text/javascript">
    function Delete(id)
    {

      var conf=confirm('Are you want to delete');
      if (conf) 
      {
          $.ajax({
          url:'admin/delet_data',
          type:"post",
          data:{dlt_id:id},
          });
      }

    }
  </script>

I want the id in this function

 public function delet_data()
{
    echo $this->input->post('dlt_id'); exit;    
}
  • 写回答

1条回答 默认 最新

  • doulang5323 2018-10-15 12:16
    关注

    concatenate the id with url

    js

     url:'admin/delet_data'+id,
    

    then use function like this in controller

    Controller

    public function delet_data($id)
    {
        echo $id;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?