Welcome Guest, Not a member yet? Register   Sign In
Ajax dynamic data fetch
#1

(This post was last modified: 12-03-2016, 01:27 AM by sheenam.)

Hi all,

i want to fetch the data dynamically from two tables
my model , view and controller are as follows
VIEW


PHP Code:
[code][php  <div class="form-group">
 
           <label for="contact_type" class="col-sm-1 hidden-xs control-label hidden col-xs-2"><?php echo get_phrase('contact_type');?>: </label>
            <div class="col-sm-5 col-xs-5">
          <select name="role" id="role" class="form-control bottom-border" required>
                    <option value=""><?php echo get_phrase('roles');?> *</option>
                    <?php
                  
                    foreach 
($roles as $role) { 
 
                   ?>
                        <option value="<?=$role->role_id?>"><?=$role->role_name?></option>
                    <?php ?>
                </select>
            </div>
            <div class="col-sm-5 col-xs-5">
                <select name="assigned_to" id="assigned_to" class="form-control bottom-border" required>
                    <option value=""><?php echo get_phrase('assigned_to');?> *</option>

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

// THIS IS MY SCRIPT//
<script>
   //AJAX call for getting items for selected supplier
   $('select#role').change(function() {
       var contact_type = $(this).val();
      // console.log(role);
       var link = '<?php echo base_url()?>'+'index.php/deals/get_contacts_ajax/'+contact_type;
       $.ajax({
           supplier_id: contact_type,
           url: link
       }).done(function(option) {
//            console.log(option);
           if (option) {
               $('#assigned_to').html(option);
           }else{
               $('#assigned_to').html('<option><?php echo get_phrase('no_record_found'); ?></option>');
           };
           rowOption = option;
       });
   });

</script>


[/php]





CONTROLLER
PHP Code:
 public function get_contacts_ajax($type)
 
   {
 
       if (!is_numeric($type)) return FALSE;
 
       $items $this->deal_model->get_contacts_ajax($type);
 
       $str '<option value="">'.get_phrase('select').' *</option>';
 
       if ($type == 1) {
 
           foreach ($items as $value) {
 
               $str.='<option value="'.$value->role_id.'">'.$value->role_id.' '.$value->role_name.'</option>';
 
           }
 
       }else{
 
           foreach ($items as $value) {
 
               $str.='<option value="'.$value->role_id.'">'.$value->name.'</option>';
 
           }
 
       }
 
       echo $str;
 
   }
 
    
MODEL
PHP Code:
public function get_contacts_ajax($type)
 
   {
 
       
         
        return $this
->db->get('users')->result();
 
   

i have to fetch the details from roles and users in which i have to fetch role names from roles table and user-name from users with reference to role_id . i tried to do that but i am unable to get the results. 
i am able to get the different roles from database but how do i get the users related to that id using AJAX
please help me !!

Thanku in Advance.
Reply


Messages In This Thread
Ajax dynamic data fetch - by sheenam - 12-03-2016, 01:26 AM
RE: Ajax dynamic data fetch - by neuron - 12-03-2016, 02:13 AM
RE: Ajax dynamic data fetch - by sheenam - 12-04-2016, 10:19 PM
RE: Ajax dynamic data fetch - by InsiteFX - 12-05-2016, 04:05 AM
RE: Ajax dynamic data fetch - by sheenam - 12-05-2016, 04:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB