gpt4 book ai didi

javascript - jQuery隐藏ajax优化

转载 作者:行者123 更新时间:2023-12-02 17:32:17 25 4
gpt4 key购买 nike

jQuery('select[field]').each(function(){
var jobj = $(this);
var pre_field_name = jobj.attr('filtered_by');
var parent_field_name = jobj.attr('field');
var data_url =jobj.attr('data-url');
var val = jobj.val();
$('select[name='+parent_field_name+']').change(function(){
console.log('change');
if($(this).val()){
console.log('ajax');
$.get(data_url, {'pk': $(this).val()}, function(response){
console.log('response');
var options = '';
for (var i = 0; i < response.length; i++) {
options += '<option value="' + response[i].value + '" '+ (val==response[i].value?'selected="selected"':'') + '>' + response[i].display + '</option>';
}
jobj.html(options);
jobj.change();
})
} else {
jobj.html('<option value="">------</option>');
jobj.change();
}
}).change();

})

如果我的页面上有 3 个元素满足此 jQuery('select[field]') 选择器 - 那么,在 chrome 日志中我会看到 6 个(由 .change 翻倍) ()我猜)响应日志记录。但在 chrome 控制台的 network 选项卡和服务器日志中,我看到只有一个请求。可能是什么原因?

最佳答案

这不是隐藏优化,而是documented缓存 http 响应的行为,

缓存

If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

关于javascript - jQuery隐藏ajax优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22953513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com