Pass Value Onclick Checkbox to controller codeigniter

前端 未结 1 2053
清歌不尽
清歌不尽 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<input type="checkbox" class="chkbox" value="value1"/>
      value 2<input type="checkbox" class="chkbox" value="value2"/> 
      value 3<input type="checkbox" class="chkbox" value="value3"/>
      value 4<input type="checkbox" class="chkbox" value="value4"/>
    

    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)
提交回复
热议问题