YankeeFan (1) [Avatar] Offline
#1
Greetings all,
I spent serveral hours yesterday studying the JQuery Autocomplete UI pluging. I cannot find any examples of using the autocomplete with a call to a source file.

Every example I find is for using a static array. Instructions say I can use a url or string, but no examples of how to code this or the code in the remote file called. I've tried doing this on my own but cannot get anything to work. I have experience making .getJSON() calls and parsing the returned data, but nothing I do works for the autocomplete as I try it.

Would anyone know of a tutorial or example site that uses a remote file in the autocomplete usage?

Here is a small sample of what I'm trying to do:

HTML form element:

Codes: <input type="text" id="codes" size="5" />

JQuery call:

$(document).ready(function() {
$('#codes').autocomplete("get_account_codes.php");
});

PHP5 on remote file (same server same directory as html and javascript)

<?php <br /> require_once('our_db_connection.php');
$term = !empty($_GET['term'])?$_GET['term']:'';
$data = '';
if( !empty($term) ){
$data=array();
$dbh = OUR_DB::getConnection('username');
if(!empty($term)){
$sql="select distinct upper(trim(object_code)) as object_code
from username.object_codes
where code_type like upper(?)
order by object_code";
$results=$dbh->queryChecked($sql, array($term));
while($d=$results->fetchRow(DB_FETCHMODE_ASSOC)){
$data[]=$d;
}
}
print json_encode($data);
}
?>

I've also tried printing out the data from my remote source as a plain array, as in:

while($d=$results->fetchRow(DB_FETCHMODE_ASSOC)){
$data[]=$d['OBJECT_CODE'];
}
print json_ecode($data);
}

... but this does not work.

Any thoughts on what I'm doing wrong would be greatly appreciated. Thanks.

also, any way to highlight and format code samples in this forum?