0

私は2つのファンシーボックスモーダル、州と都市のコンボボックスを持っています。州を選択した後、コンボ都市をロードする必要があります。私のコード:

<div id="city" class="hide">

    <asp:Literal ID="litCity" runat="server"></asp:Literal>
    <a href="#data">Trocar de Cidade</a>

</div>

<asp:UpdatePanel ID="updCity" runat="server" UpdateMode="Conditional">
<ContentTemplate>

    <div id="data" class="hide">

    <asp:HiddenField ID="hdnNovaCidade" runat="server" Value="" />
    <div class="row">

    <label for="drpState">Estado *</label>
    <asp:DropDownList ID="drpState" runat="server" AutoPostBack="True" > </asp:DropDownList>

    </div>

<div class="row">

    <label for="drpCity">Cidade *</label>
    <asp:DropDownList ID="drpCity" runat="server"></asp:DropDownList>


</div>

    <input id="btCidade" type="submit" value="Escolher Cidade" />

</div>
</ContentTemplate>
<Triggers>

    <asp:AsyncPostBackTrigger ControlID="btCarregaCidade" EventName="Click" />

</Triggers>
</asp:UpdatePanel>

Jクエリ

$('[id$="drpState"]').change(function () {

    $('[id$="hdnState"]')[0].value = $(this).val();
    $('[id$="btCarregaCidade"]')[0].click();

});

イベント ボタンの後にページがリロードされ、ファンシー ボックスが閉じられます。モーダルを閉じずにコンボボックスの都市をロードするにはどうすればよいですか?

手伝ってくれてありがとう

4

1 に答える 1

0

この目的のためにAjaxを使用することをお勧めします..詳細なコードは、最初にid = "citycontainer"で状態選択ボックスの近くに空のスパンまたはdivを配置します

$('[id$="drpState"]').change(function () {
var stid = $(this).val();
var cityhtml = '';
         //call an ajax function to load the states
    $.ajax({
      url:'Your_url_containing_thephp_function_for_states',
      data : {'stateid',stid},
      dataType:'json',
      type: "POST",
      success:function(msg){
             cityhtml+='<select id="city">';
                if(count(msg)>0){
                for(i=0;i<msg.length;i++){

             cityhtml+='<option value="'+msg[i]['your_city_id_index']+'">'+msg[i]['your_city_name_index']+'</option>';
                 }
             }
$('#citycontainer').html(cityhtml);
      }    
});


});

//State.php (The php side)

$stateid = $_POST['stateid'];
$cities = someFuntionReturningCitiesbasedOnstateid($stateid); //must return as array
echo json_encode($cities);exit;
于 2012-06-25T03:40:45.143 に答える