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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析