我想填充一些下拉字段。我有以下的下拉菜单:AJAX接收多个数据
- 大陆
- 国家
- 体育
我想选择第一块大陆,在这之后的国家和体育动态填充。例如:
欧洲 - >(所有欧洲国家都显示正确,它们以db表示)。
我选择阿尔及利亚;运动名称应该出现在下拉菜单中。 json是正确的,但我知道,ajax是错误的! 这里是我的代码:
$(document).ready(function(){ $('#select_continents').on('change', function(){ //continent drop down ID $('#select_countries').empty();// country drop down ID $('#select_sport').empty();// sport drop down ID $.ajax({ method: 'GET', url: './json.php', data: { json_continent_country : 1, continent : $('#select_continents').val(), json_country_sport : 1, country : $('#select_countries').val() } }) .done(function(data){ $.each(JSON.parse(data), function(i, val) { $('#select_countries').append('<option value="'+val.id+'">'+val.country_name+'</option>'); $('#select_sport').append('<option value="'+val.id+'">'+val.sport_name+'</option>'); }) }) .fail(function(){ alert('error'); }) }) })
这就是我得到:
有什么建议?
试试这个例子:http://www.plus2net.com/php_tutorial/ajax_drop_down_list-demo.php – Chester