0

ラジオボタンは2つ。クリックしたものに応じて、ドロップダウン ボックスにそのデータ セットが読み込まれます。最初にクリックしたものにもよりますが、それはロードに約 1 ~ 2 秒かかりますが、他のものはすぐにロードされます。前後にクリックしても。なぜ、そしてどうすればすぐにロードを停止できるのだろうと思っていました(奇妙なことに、私は知っています)。

$('#rblGenre').change( function() {
    $('#ddlSpecificGenre').attr('disabled','disabled').html( '<option>Loading...</option>' )
    var genre = $(this + ':checked').val();

    $.ajax({
        type: 'GET',
        url: '../bookGenres.xml',
        dataType: 'xml',
        success: function( xml ) {
            var xmlGenre = $(xml).find( genre );
            $('#ddlSpecificGenre').removeAttr('disabled').children().remove();
            xmlGenre.children().each( function() {
                $('#ddlSpecificGenre').append( '<option>' + $(this).text() + '</option>' );
            });
        }
    });
});

<asp:RadioButtonList ID='rblGenre' runat='server'>
    <asp:ListItem Text='Fiction' Value='Fiction'></asp:ListItem>
    <asp:ListItem Text='Non-Fiction' Value='Non-Fiction'></asp:ListItem>
</asp:RadioButtonList>

<asp:DropDownList ID='ddlSpecificGenre' runat='server' Enabled='false'>
    <asp:ListItem Text='Choose a Genre' Selected='True'></asp:ListItem>
</asp:DropDownList>
4

1 に答える 1

0

あなたの応答がキャッシュされているように思えます。jQuery を使用してキャッシュをオフにする場合は、「ajax」呼び出しの設定リストに「cache: false」を追加します。

したがって、関数呼び出しは次のようになります。

$.ajax({
    type: 'GET',
    url: '../bookGenres.xml',
    dataType: 'xml',
    cache: false,
    success: function( xml ) {
        var xmlGenre = $(xml).find( genre );
        $('#ddlSpecificGenre').removeAttr('disabled').children().remove();
        xmlGenre.children().each( function() {
            $('#ddlSpecificGenre').append( '<option>' + $(this).text() + '</option>' );
        });
    }
});
于 2010-07-07T20:18:43.227 に答える