这是 html 我的代码
<input type="text" name="country" id="country"/>
<input type="text" name="city" id="city"/>
这是我的jQuery代码
$(document).ready(function() {
$('#country').keydown(function(){
$(this).autocomplete({
source: "get_country.php",
minLength: 0,
autoFocus: true,
select: function(event, ui)
{
}
});
});
var country = $("#country").val();
$('#city').keydown(function(){
$(this).autocomplete({
source: "get_city.php",
//type:"GET",
data : 'country='+country,
minLength: 0,
autoFocus: true,
select: function(event, ui)
{
}
});
});
});
这是我的代码 get_city.php
include_once('config.php');
if ( !isset($_REQUEST['term']) )
exit;
$country = $_POST['country'];
$rs = mysql_query('select city from xyz_table where country="$country" and city like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by city asc limit 0,10');
$data = array();
if ( $rs && mysql_num_rows($rs) )
{
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
$data[] = array(
'value' => $row['city']
);
}
}
echo json_encode($data);
flush();
这里显示了以下问题注意:未定义的索引:第6行G:\xampp\htdocs\xyz\get_city.php中的国家
我在自动完整搜索中获得了国家/地区,例如德国,英国
我想在国家(例如德国/英国)下获得自动完整搜索城市
我该如何解决它,请任何建议