为什么jQuery ID不适用于ajax中的下拉列表


Why jQuery ID not worked with dropdown IN ajax

我使用Ajax在PHP中填充下拉列表,但我在Ajax中使用的ID与Jquery ID相同。因此数据不会进入第二个下拉列表。这是我的jquery代码:

<script type="text/javascript">
    var n = jQuery.noConflict();
    n(function () {
        n("#country_id").selectbox();
    });
    n(function () {
        n("#country_id1").selectbox();
    });
    n(function () {
        n("#country_id2").selectbox();
    });
    n(function () {
        n("#country_id3").selectbox();
    });
</script>

这是我的ajax代码:

<script type="text/javascript">
  function get_stream(){
    var country_id=jQuery("#country_id").val();
    //alert(country_id);
    jQuery.ajax({
        type: "POST",
        url: '<?php echo Router::url(array('controller'=>'Prep','action'=>'stream'));?>',
        data: {stream:country_id},
        success: function (data){
            //alert(data);
            jQuery('#country_id1').html(data);
        }
    });
  }
</script>

这是我的html

       <div class="selectbox">
            <select  name="data[Jobboard][City]" id="country_id1"       tabindex="1">
                <option>select City</option>
            </select>
       </div>

我必须做些什么才能在第二个下拉列表中获得数据?

尝试替换这个

jQuery("#country_id").val();

$( "#country_id option:selected" ).text();

希望这能有所帮助。。

您应该尝试以下操作:$("#country_id").next('.sbHolder').find('.sbSelector').html('Spain')