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;
    }
    
    打赏 评论

相关推荐 更多相似问题