1
是我不知道如果我累了,或者爲什麼我不能得到它的權利,請幫助我需要的JSON獲取表單值使用AJAX
<script language="javascript">
$(document).ready(function(){
getResultsCountry();
})
function getResultsCountry() {
$.ajax({
url:'suggest_country.html',
type:'POST',
data: 'q=',
dataType: 'json',
success: function(json) {
$('#country')[0].options.length = 0;
$.each(json, function(i, value) {
if (value=='<?php echo $country; ?>') {
$('#country').append($('<option>').text(value).attr('value', value).attr('selected', 'selected'));
} else {
$('#country').append($('<option>').text(value).attr('value', value));
};
});
}
});
};
</script>
代碼在外部文件看起來像
<?php
$results = mysql_query('SELECT DISTINCT country FROM MyTable WHERE country LIKE \'%\' ORDER BY country');
while($result = mysql_fetch_array($results)) {
$cities = $cities.' short = \''.$result['country'].'\' OR';
}
$cities = substr($cities, 1,strlen($cities)-3);
$results2 = mysql_query('SELECT full, short FROM `Countries` WHERE '.$cities);
$json = array();
while($result2 = mysql_fetch_array($results2)) {
$json[] = $result2['short'].','.$result2['full'];
}
echo json_encode($json);
mysql_close($db2);
?>
響應我越來越是
["AG,ANTIGUA AND BARBUDA","AU,AUSTRALIA","BR,BRAZIL","CA,CANADA","KY,CAYMAN ISLANDS","CN,CHINA"]
我需要的是填寫它的選項標籤我也得到這部分,但我不能讓它填充c國家代碼AG作爲價值和名稱像名稱一樣
<option value="AG">Antigua</option>
請爲我打破它我真的很困惑和厭倦了它的小時頭痛。
I t發生什麼事情是你沒有花時間跟進你的[其他](http://stackoverflow.com/questions/5925246/how-to-separate-json-response-in-two-variables)問題和只是轉發它看看是否有人可以把你的代碼和修復它? – R0MANARMY 2011-05-14 15:47:00