Так что иди с JSON:)
$("#names").autocomplete({
source: function(request , response){
$.ajax({
type: 'GET',
url: 'name.php',
dataType: "json",
В вашем 'name.php' выполните следующие действия
<?php
// do all your code here, get names etc....
// lets say your array with names looks like this
// $names = array('Peter', 'John', 'Tom', 'Andy');
// serialize the array and send it to the browser
echo json_encode($names); <b>// edited here</b>
?>
В вашем файле .js ...
var names = jQuery.parseJSON('["Peter","John","Tom","Andy"]');
// just to try, if this works, uncoment alert() below this
//alert( names[3] );
Итак, мой полный код будет выглядеть так:
$("#names").autocomplete({
source: function(request , response){
$.ajax({
type: 'GET',
url: 'name.php',
dataType: "json",
data: "letter="+request,
success: function(data) {
var names = jQuery.parseJSON(data);
}
});
response(names);
},
minLength: 1
});