I'm having the same or similar problems with Autocomplete. After several days of research, I figured out how to pass a country and the user's typing for state as the term to a php script that uses both data to construct a query. The query executes correctly, an array of JSON objects is constructed, but no dropdown list forms for the state input box to make a selection of the state. I suspect the success function, but can't find a solution. Do any of you see the problem? Here's my code.
Autocomplete ajax: $("#stateProvince").autocomplete
({
source: function( request, response )
{
$.ajax(
{
url: "getStateProvince.php",
data: {
term: request.term,
country: $('input[name=country]:checked').val(), //Pass the selected country to php
},
type: "POST", // a jQuery ajax POST transmits in querystring format in utf-8
dataType: "json", //return data in json format
success: function( data )
{
response( $.map( data, function( item )
{
return{
label: item.stateName,
value: item.stateAbbrev
}
}));
}
});
},
minLength: 2
});
selected php: while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC))
{
/* In each row, pull stateProvinceNameInEnglish and stateProvinceAbbreviation. */
$row_array['stateName'] = $row['stateProvinceNameInEnglish'];
$row_array['stateAbbrev'] = $row['stateProvinceAbbreviation'];
array_push($return_arr,$row_array);
}
/* Toss back state or province results as a json encoded array. */
echo json_encode($return_arr);
example of returned data return_arr:[{"stateName":"New Hampshire","stateAbbrev":"NH"},{"stateName":"New Jersey","stateAbbrev":"NJ"},{"stateName"
:"New Mexico","stateAbbrev":"NM"},{"stateName":"New York","stateAbbrev":"NY"}]