document.fonts.ready.then为什么要考虑同步XMLHttpRequest

时间:2018-09-04 01:40:41

标签: ajax asynchronous xmlhttprequest synchronous

声明字体时:浏览器倾向于等待带有此字体的文本来加载.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 (); });

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

这最终会被阻止吗?

1 个答案:

答案 0 :(得分:0)

我发现的解决方法是使div的显示隐藏

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.javytharanee.quicksolattendance, PID: 6602
                  com.google.firebase.database.DatabaseException: Failed to convert value of type java.util.HashMap to String
                      at com.google.android.gms.internal.zzepg.zzb(Unknown Source:93)
                      at com.google.android.gms.internal.zzepg.zza(Unknown Source:0)
                      at com.google.firebase.database.DataSnapshot.getValue(Unknown Source:10)
                      at com.javytharanee.quicksolattendance.ClientLIstActivity$2.onChildAdded(ClientLIstActivity.java:53)
                      at com.google.android.gms.internal.zzegg.zza(Unknown Source:71)
                      at com.google.android.gms.internal.zzelk.zzcal(Unknown Source:2)
                      at com.google.android.gms.internal.zzelq.run(Unknown Source:71)
                      at android.os.Handler.handleCallback(Handler.java:873)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:193)
                      at android.app.ActivityThread.main(ActivityThread.java:6669)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

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

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