[eluser]afro[/eluser]
I am trying to load a record from the db using AJAX to pick the value of the staffid field using the .blur()
function pass to the controller and to the model to pick a record which has its StaffId equal to the staffid value
passed from the view. am getting the following error.
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: record
Filename: views/leave.php
Line Number: 89
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/leave.php
Line Number: 89
The controller function as as follows
Code:
public function load_staff_data()
{
$this->load->model('user_model', '', TRUE);
$staffid = trim($_POST['staffid']);
$results = $this->user_model->get_staff_data($staffid);
}
And the model is as follows
Code:
public function get_staff_data($staffid)
{
$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;
}
The AJAX function is here below
Code:
[removed]
$(document).ready(function()
{
$('#leaveaplication').find('#staffid').blur(function()
{
var staffid = $('#staffid').val();
$.post('/index.php/home/load_staff_data',
{ 'staffid':staffid },
function(result) {
$('#bad_username').replaceWith('');
if (results) {
$('#staffid').after('<div id="bad_username" style="color:red;">' +
'<p>(That StaffId does not exits. Please type the correct Staff Id:)</p></div>');
}
}
);
});
});
[removed]