douwo1862 2018-05-24 02:44
浏览 125
已采纳

调用控制器并通过onclick监听器传递值

<?php 
    foreach($fetch_file as $row)
    {   
        echo '<tr>';
        echo '<td>' . base64_decode($row->file_perm_desc) . '</td>';
        echo '<td style = "text-align:center;">' . date_format((date_create($row->date_entry)),"M d, Y")  . '</td>';
        echo '<td class = "text-center"><a class="btn btn-info" >
        <input type = "hidden" name = "editid" class = "openid" value = ' . $row->file_perm_id . '>
        <i class="glyphicon glyphicon-folder-open"></td>';
        echo '<td class = "text-center"><a class="btn btn-warning" >
        <input type = "hidden" name = "editid" class = "unpublishid" value = ' . $row->file_perm_id . '>
        <i class="glyphicon glyphicon-comment"></td>';
        echo '<td class = "text-center"><a class="btn btn-danger" >
        <input type = "hidden" name = "editid" class = "deleteid" value = ' . $row->file_perm_id . '>
        <i class="glyphicon glyphicon-trash"></td>';
        echo '<td class = "text-center"><a class="btn btn-success" >
        <input type = "hidden" name = "editid" class = "downloadid" value = ' . $row->file_perm_id . '>
        <i class="glyphicon glyphicon-download"></td>';
        echo '</tr>';

     }      
?>  


  $('.btn-info').click(function()
    {
        var id = $(this).find('.openid').val();
        window.location.replace("<?php echo base_url();?>ClientCont/List_Files");


    });

I have this onlick listener from the value above on the user click the button it should go to the controller but I dont know how can I call controller and pass the value from id. this is in codeigniter framework hope somebody can help thanks

  • 写回答

2条回答 默认 最新

  • dtwncxs3547 2018-05-24 05:13
    关注

    Hope this will help you :

    $('.btn-info').click(function() {
      var id = $(this).find('.openid').val();
      if (id) 
      {
         window.location.href = "<?php echo base_url('ClientCont/List_Files/');?>" + id;
      }
    
    });
    

    Your controller's List_Files method should be like this :

    public function List_Files($id)
    {  
       /*echo passed id from the js here like this */
    
       echo $id;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?