在我下面的代码中,选择框的城市不会根据所选状态使用jquery动态改变


cities of select box are not dynamically changing based on the selected state using jquery in my below code

下面是Jquery代码

$("#state").change(function(){
    $.ajax
    ({
        url: "www.myweb.com/ajax.abc.php",
        type: "POST",
        data: {state: function(){return $("#state").val()}}; /* i have given stateId as value*/
        cache: false,
        success: function(html)
        {
            $('#city').find('option').remove().end().append(html);
        } 
    });

下面的代码表示在ajax文件(即ajax.abc.php)

if(isset($_POST['state']))
{
$getCity = mysql_query('SELECT * FROM tblCity WHERE stateId = '.$_POST['state']);
while($fetchCity = mysql_fetch_array($getCity))
{
    echo '<option value="'.$fetchCity["cityName"].'">'.$fetchCity["cityName"].'</option>';
}
}

换行:

$('#city').find('option').remove().end().append(html);

分为两部分:

$('#city').find('option').remove();
$('#city').append(html);

现在,您正在删除option,但随后调用append,这显然是行不通的。