JavaScript console.log causes error: “Synchronous XMLHttpRequest on the main thread is deprecated…”

后端 未结 21 1704
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 09:26

I have been adding logs to the console to check the status of different variables without using the Firefox debugger.

However, in many places in which I add a

21条回答
  •  隐瞒了意图╮
    2020-11-22 09:45

    This happened to me when I was being lazy and included a script tag as part of the content that was being returned. As such:

    Partial HTML Content:

    SOME CONTENT HERE

    It appears, at least in my case, that if you return HTML content like that via xhr, you will cause jQuery to make a call to get that script. That call happens with an async flag false since it assumes you need the script to continue loading.

    In situations like this one you'd be better served by looking into a binding framework of some kind and just returning a JSON object, or depending on your backend and templating you could change how you load your scripts.

    You could also use jQuery's getScript() to grab relevant scripts. Here is a fiddle, It's just a straight copy of the jQuery example, but I'm not seeing any warnings thrown when scripts are loaded that way.

    Example

    
    

    http://jsfiddle.net/49tkL0qd/

提交回复
热议问题