单击单选按钮时的 Ajax 调用有时会在即时到约 2 秒之间交替
有 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>
There are 2 radio buttons. Depending on which one you click, the drop down box will load that set of data. Depending on the first one I click, that one will take about 1-2 secs to load, while the other loads instantly. Even click back and forth. I was wondering why, and how I might be able to have it stop loading instantly (weird, I know).
$('#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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您的回复已被缓存。如果您想使用 jQuery 关闭缓存,请将“cache: false”添加到“ajax”调用中的设置列表中。
所以你的函数调用将变成:
Sounds to me like your response is getting cached. If you want to turn off caching using jQuery, add "cache: false" to your list of settings in your "ajax" call.
So your function call would become: