CodeIgniter:依赖下拉列表不起作用

时间:2015-07-13 05:16:54

标签: php jquery codeigniter

我的控制人员: -

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cnewincident extends CI_Controller
{       
    public function __construct()
    {
        parent::__construct();        
        $this->load->database();
    }
    public function index()
    {            
        $this->load->model('users/supervisor/Mnewincident');
        $data['category'] = $this->Mnewincident->getCatgories();  
        //loads up the view with the query results  
        $this->load->view('users/supervisor/vnewincident',$data);

        if($this->input->post('addrequest'))
        {                
            $this->load->model('users/supervisor/Mnewincident');
            // to get the username from table who is creating  this request
            $session_data = $this->session->userdata('emailid');
            $firstname =  $this->Mnewincident->get_firstname($session_data);

            // passing that usename in newincident table
            if($this->Mnewincident->add_request($firstname))
            {
                $this->session->set_flashdata( 'message', 'Request added successfully.' );
                redirect('users/supervisor/Cnewincident');
            }
            else
            {
                $this->session->set_flashdata( 'message', 'Failed to add the request. Try again' );
                redirect('users/supervisor/Cnewincident');
            }
        }
    }
    //call to fill the second dropdown with the subcategories
        public function loadsubcat()  
        {  
           echo $category_id = $this->input->post('id',TRUE);
           $subcatData['subcatDrop']=$this->Mnewincident->getSubcatgories($category_id);  
           $output = null;  
           foreach ($subcatData['subcatDrop'] as $row)  
           {  
              $output .= "<option value='".$row->subcategory_description."'>".$row->subcategory_description."</option>";  
           }  
           echo $output;  
        } 
}

?>

我的模特: -

 class Mnewincident extends CI_Model
 {
     public function __construct()
    {
        $this->load->database();
    }

       public function getCatgories()  
       {  
          $this->db->select('category_id,category_description');  
          $this->db->from('tbl_categorymaster');  
          $query = $this->db->get();
          foreach($query->result_array() as $row)
          {  
             $data[$row['category_id']]=$row['category_description'];  
          }
          return $data;  
       }  

       public function getSubcatgories($category_id=string)  
       {  
          $this->db->select('srno,subcategory_description');  
          $this->db->from('tbl_subcategorymaster');  
          $this->db->where('category_id',$category_id);  
          $query = $this->db->get();  
          return $query->result();  
       } 
}

我的观看代码: -

              $(document).ready(function() {  
                 $("#category").change(function(){                       
                 $.ajax({  
                    url:"<?php echo base_url()."users/supervisor/Cnewincident/loadsubcat"?>",  
                    data: {id:$(this).val()},  
                    type: "POST",  
                    success:function(data){  
                    $("#subcategory").html(data);  
                 }  
              });  
           });  
        });  

1 个答案:

答案 0 :(得分:0)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="testimonials">
  <ul class="banner_testi">
    <a href="javascript:void(0)" class="unslider-arrow prev testi"><</a>
    <a href="javascript:void(0)" class="unslider-arrow next testi">></a>
    <li>One Line Quote<span>Client Name</span>
    </li>

    <li>Three
      <br>Line
      <br>Quote<span>Client Name</span>
    </li>

    <li>Two Line
      <br>Quote<span>Client Name</span>
    </li>
  </ul>
</div>

希望它有效.....