【问题标题】:document.fonts.ready.then why considered Synchronous XMLHttpRequestdocument.fonts.ready.then 为什么考虑同步 XMLHttpRequest
【发布时间】:2018-09-04 21:12:28
【问题描述】:

当声明 font-face 时:浏览器倾向于等待具有此字体的文本来加载 .ttf 或 .otf ...

我发现了这段代码

document.fonts.ready.then(function () { });

当我尝试时

function myAajax () {
    var xhr = new XMLHttpRequest(); 
    xhr.open("POST", "ajax.php", true);
    ...
    xhr.send(params);
}

document.fonts.ready.then(function () { myAajax (); });

我明白了 [Deprecation] Synchronous XMLHttpRequest... 在 chrome 控制台日志中...

这最终会被阻止吗?

【问题讨论】:

标签: ajax asynchronous xmlhttprequest synchronous


【解决方案1】:

我找到的解决方法是制作一个隐藏显示的 div

<div id="ajaxContent" style="display:none;"></div>

然后调用我的 ajax,当字体准备好时,显示 div...

myAajax ();
document.fonts.ready.then(function () {$("#ajaxContent").show(); });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2013-05-17
    • 1970-01-01
    相关资源
    最近更新 更多