I'm using php to fetch the data from mysql database and then use that data on the jquery ui autocomplete. But it seems like the JSON that is returned doesn't match what jquery ui needs. The JSON returned looks something like this:
["dyes miran famint","annie ferrer mendrez","annie ferrer mendrez","anton setra masgre","anton setra masgre","jeniffer hades cruz","jeniffer hades cruz","alvin louie urbano maranon","alvin louie urbano maranon","francisza jerrielleza bullonza","blaze br tags anchor"]
I even used jQuery.parseJSON on it.
And here's what I did on the php file:
$class_code = $_POST['class_code'];
$student_list = array();
$students = mysql_query("SELECT accounts.id, fname, mname, lname, classcode
FROM account_details
LEFT JOIN accounts ON account_details.id = accounts.id
LEFT JOIN class_rooster ON accounts.id = class_rooster.id
WHERE accounts.status = 1 AND accounts.type='student'
AND (class_rooster.id IS NULL OR classcode !='$class_code')");
$students_num = mysql_num_rows($students);
if($students_num > 0){
while($row = mysql_fetch_assoc($students)){
$student_list[] = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
}
echo json_encode($student_list);
Here's the error that I'm getting:
Uncaught TypeError: Property 'source' of object #<Object> is not a function
Here's the JavaScript:
function get_students(){
var class_code = $('#current_classes').val();
$.post('student_list.php', {'class_code' : class_code},
function(data){
return data;
}
);
}
$("#student_name").live('click', function(){
$("#student_name").autocomplete({
source: get_students()
});
});