如何强制刷新 Chrome,Safari
How to force refresh Chrome, Safari
在我的站点中,我有一个下载 JSON 数据的过程。这期间,我全屏显示了一个 div 旋转。
对于 FF 和 IE,div 在开始下载之前是可见的,但对于 Chrome 和 Safari 则不可见。
JSFiddle link 此处:https://jsfiddle.net/r6s0cr31/4/,背景颜色在 Chrome 和 Safari 上不会改变,对于 IE 和 FF,背景颜色之前会改变。
$('#mapLoading').show();
$.ajaxSetup({async: false});
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
}
)
$('#mapLoading').hide();
如果我在 console(chrome) 中放置一个停止点在 getJSON 之前,我可以看到 div 正确显示。
我尝试在没有 JQuery 的情况下在纯 JS 中做到这一点,但问题似乎是一样的。
在此先感谢您的帮助
似乎 Chrome 和 Safari 运行 函数在执行后首先重新呈现页面内容。因此没有看到任何变化。
正如 Andy Chen 已经写过的,即使在用户体验方面,异步也更好:
$('#btn').click(function(){
$('#mapLoading').show();
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
/* ...code here... */
$('#mapLoading').hide();
}
)
})
您正在使用与 chrome 代码冻结无关的已弃用的异步错误 ajax 调用超时将解决问题
setTimeout(function () {
$.ajaxSetup({async: false});
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
}
)
$('#mapLoading').hide();
}, 20);
在您的情况下,代码已执行,但在回调后可见
在这里 fiddle 工作 https://jsfiddle.net/r6s0cr31/5/
不使用同步(冻结浏览器),使用异步并在获得响应后隐藏它可以解决问题:
$('#btn').click(function(){
$('#mapLoading').show();
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true")
.then(function(response){
$('#mapLoading').hide();
})
})
感谢您的回复,我了解到:
- 没有异步请求冻结 Chrome & Safari
- Chrome 和 Safari 运行 功能优先,然后更新页面设计。
再次感谢
在我的站点中,我有一个下载 JSON 数据的过程。这期间,我全屏显示了一个 div 旋转。 对于 FF 和 IE,div 在开始下载之前是可见的,但对于 Chrome 和 Safari 则不可见。
JSFiddle link 此处:https://jsfiddle.net/r6s0cr31/4/,背景颜色在 Chrome 和 Safari 上不会改变,对于 IE 和 FF,背景颜色之前会改变。
$('#mapLoading').show();
$.ajaxSetup({async: false});
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
}
)
$('#mapLoading').hide();
如果我在 console(chrome) 中放置一个停止点在 getJSON 之前,我可以看到 div 正确显示。 我尝试在没有 JQuery 的情况下在纯 JS 中做到这一点,但问题似乎是一样的。
在此先感谢您的帮助
似乎 Chrome 和 Safari 运行 函数在执行后首先重新呈现页面内容。因此没有看到任何变化。
正如 Andy Chen 已经写过的,即使在用户体验方面,异步也更好:
$('#btn').click(function(){
$('#mapLoading').show();
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
/* ...code here... */
$('#mapLoading').hide();
}
)
})
您正在使用与 chrome 代码冻结无关的已弃用的异步错误 ajax 调用超时将解决问题
setTimeout(function () {
$.ajaxSetup({async: false});
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true",
function( response ) {
}
)
$('#mapLoading').hide();
}, 20);
在您的情况下,代码已执行,但在回调后可见
在这里 fiddle 工作 https://jsfiddle.net/r6s0cr31/5/
不使用同步(冻结浏览器),使用异步并在获得响应后隐藏它可以解决问题:
$('#btn').click(function(){
$('#mapLoading').show();
$.getJSON("https://router.project-osrm.org/route/v1/driving/0,40;0,42?overview=full&alternatives=true&steps=true")
.then(function(response){
$('#mapLoading').hide();
})
})
感谢您的回复,我了解到: - 没有异步请求冻结 Chrome & Safari - Chrome 和 Safari 运行 功能优先,然后更新页面设计。
再次感谢