2014-03-12 14 views
0

下面使用jquery选定状态改变是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>'; 
} 

} 
+0

你是否进入'成功'?意味着你的ajax调用有效吗? –

回答

0

打破这一行:

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

分为两个部分:

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

眼下,要卸下option,但随后调用append就可以了,这显然是行不通的。

相关问题