0

これは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();

ここに問題通知の下に示されています:未定義のインデックス:G:\ xampp\htdocs\xyz\get_city.phpの6行目の国

ドイツ、イギリスなどのオートコンプリート検索で国を取得しました

国の下の都市をオートコンプリート検索したい (ドイツ/イギリスなど)

どうすれば解決できますか、何か提案をお願いします

4

1 に答える 1

1

これを変える

$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');

$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");

違いを参照してください クエリ$countryでは、実際の ではなく文字列として設定されていましたcountry

これを使って

$_REQUEST['country']

これを使ってデータを送る

data : { country : country },

country内部呼び出しを宣言する

$('#city').keydown(function(){
    var country = $("#country").val();
    $(this).autocomplete({
        source: "get_city.php",
        ............
于 2013-03-30T06:13:41.550 に答える