CodeIgniter Forums

Full Version: Codeigniter with Ajax to load data to view.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

[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

El Forum

[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