使用codeigniter中的ajax将多个复选框值传递给数据库

时间:2018-01-05 04:48:35

标签: codeigniter

iam尝试使用ajax将多个复选框值传递给数据库。但是这段代码不起作用,请帮我找到答案。这是我的jquery和ajax

    jQuery(".bus-cat-drop").change(function(event) {    
    $('.check').html("");
    var businesscategoryid = $(this).val();
     hitURL = baseURL + "user/postbusiness/get_businesscategoryid/";
    alert(baseURL + "user/postbusiness/get_businesscategoryid");

        //alert(businesscategoryid);
      jQuery.ajax({
    type : "POST",
    dataType : "json",
    url : hitURL,
    data : { categoryid : businesscategoryid } 
    }).done(function(data){

         $.each(data, function(key,value) {    
    //alert(key);  
    //alert(value.value);
     /* var opt = $('<option />');
                    opt.val(value.value);
                    opt.text(value.label);
                    $('#subcategory').append(opt);
                    $('#subcategory').get(0).selectedIndex = 1; */
                    $('.check').append("<input name=check[]:checked type=checkbox>"+value.label+"</br>");
                    $('.check').push(this.value);

    }); 
    }); 

iam尝试使用ajax将多个复选框值传递给数据库。但是这段代码不起作用,请帮我找到答案。这是我的观点。

<form client ="form" id="bus-reg-form" action="<?php echo base_url().'user/postbusiness/DirectoryCategory/'.$userId ?>" method="post" role="form">                        
                            <div class="row">       
                            <div class="col-md-6">                                
                                <div class="form-group">
                                    <label for="company">Name of Business / Company </label>
                                    <input type="text" class="form-control required" id="company" name="company" value="<?php echo $company_name;?>">

                                </div>
                                </div>                                      
                            </div>
                       <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="Category">Category</label>
                                  <select class="form-control bus-cat-drop" id="businesscategory" name="businesscategory">
                                     <option value="0">Select Category</option>
                                  <?php
                                    if(!empty($list_directorycategory))
                                        {
                                          foreach ($list_directorycategory as $rl)
                                                 {
                                                    ?>
                                            <option value="<?php echo $rl->dr_cat_id; ?>"><?php echo $rl->dr_cat_name;?></option>   
                                           <?php
                                                  }
                                        }
                                       ?>
                                  </select>
                                </div>
                            </div>
                            </div>
                            <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                <div class="subcategory-dropdown">
                                    <label for="subcategory"> Sub Category [Maximum 3 subcategory]</label>
                                   <div class="check" name="check[]" >

                                   </div>        
                                </div>
                                </div>
                            </div>

                        <div class="col-md-6">
                            <div class="form-group">
                            <div class="Business-Offer">
                              <label for="business">Business Offer / Highlights</label>
                              <textarea class="form-control required" title="Business description" id="business" rows="6" name="business"></textarea>
                            </div>
                            </div>
                        </div>
                        </div>
                        <div class="row">
                        <div class="control-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <div class="form-group">
                                <label for="Tags">Tags [Maximum 10 tags]</label>
                                <input type="text" class="form-control required" id="tags" name="tags">
                            </div>
                        </div>
                         </div>

0 个答案:

没有答案