Pass Value Onclick Checkbox to controller codeigniter

前端 未结 1 2070
清歌不尽
清歌不尽 2021-01-26 04:55

I am new to CI and i am having issues in following code: My Controller shows all the values of countries dynamically from DB, i need to pass value onclicking particular chechbox

1条回答
  •  离开以前
    2021-01-26 05:37

    HTML

      value 1
      value 2 
      value 3
      value 4
    

    Jquery Ajax

     $(document).ready(function(){
    
         $(document).on('click','.chkbox',function(){
          var id=this.value;
    
           $.ajax({
            type: "POST",
            context: "application/json",
            data: {id:id},
            url: "http://localhost/xyz/index.php/controller_name/function_name",
            success: function(msg) 
            {
                alert('result from controller');
            }
        })
       });
    
     });
    

    Controller

     public function function_name()
     {
       $id=$this->input->post('id');
       //now use the $id variable for the desired purpose.
     }
    

    0 讨论(0)
提交回复
热议问题