CodeIgniter Forums
Codeigniter with Ajax to load data to view. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Codeigniter with Ajax to load data to view. (/thread-41014.html)



Codeigniter with Ajax to load data to view. - El Forum - 04-26-2011

[eluser]afro[/eluser]
Hey guys, i would like your assistance in handling a problem with Ajax.
I have four fields in my view and i want when one of the field in filled, the other three field are load from the database
automatically using the Ajax, the page should refresh and load the three fields when the staffid field losses focus.


Codeigniter with Ajax to load data to view. - El Forum - 04-26-2011

[eluser]toopay[/eluser]
[quote author="afro" date="1303817822"]Hey guys, i would like your assistance in handling a problem with Ajax.
I have four fields in my view and i want when one of the field in filled, the other three field are load from the database
automatically using the Ajax, the page should refresh and load the three fields when the staffid field losses focus.[/quote]
:-S


Codeigniter with Ajax to load data to view. - El Forum - 04-26-2011

[eluser]afro[/eluser]
I have tried this but it is not working

Code:
$(document).ready(function() {
        
  staffid = prompt('Enter your Staff Id', $(this).find().html());
  if (staffid != null)
    {
function get_staff_data(staffid) {
  var p = {};
  p[staffid] = staffid
  $("input#staffid").load(index.php/user/load_staff_data,p,function(str){
});
}
}
            
            
});

My controller's method is here below

Code:
function load_staff_data()
    {    
$ID = $_POST[staffid];  

   $this->load->model('user_model');
   $results = $this->user_model->get_staff_data($ID);
  
   $this->load->view('leave',$results);
}

the model is as follows

Code:
public function get_staff_data($ID)
{
$this->db->select('StaffId,StaffName, Department, LeaveBalance');
$this->db->where('StaffId', $staffid);
$query = $this->db->get('staff');
   $row = $query->row();
$results[record][$row->StaffName][StaffName] = $row->StaffName;
$results[record][$row->Department][Department] = $row->Department;
$results[record][$row->LeaveBalance][LeaveBalance] = $row->LeaveBalance;

return $results;



}

can someone help me out from here