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

后端 未结 21 1708
爱一瞬间的悲伤
爱一瞬间的悲伤 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:34

    The question raised in 2014 and it's 2019 so I guess it's good to look for better option.

    You can simply use fetch api in Javascript which provide you more flexibility.

    for example, see this code

    fetch('./api/some.json')
        .then((response) => {
            response.json().then((data) => { 
                ... 
            });
        })
        .catch((err) => { ... });
    
    0 讨论(0)
  • 2020-11-22 09:38

    I fixed this with below steps:

    1. Check your CDN scripts and add them locally.
    2. Move your scripts includes into the header section.
    0 讨论(0)
  • 2020-11-22 09:39

    It was happening to me in ZF2. I was trying to load the Modal content but I forgot to disable the layout before.

    So:

    $viewModel = new ViewModel();
    $viewModel->setTerminal(true);
    return $viewModel;
    
    0 讨论(0)
  • 2020-11-22 09:42

    Like @Nycen I also got this error because of a link to Cloudfare. Mine was for the Select2 plugin.

    to fix it I just removed

     src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"
    

    and the error went away.

    0 讨论(0)
  • 2020-11-22 09:44

    I get such warning in following case:

    1) file1 which contains <script type="text/javascript" src="/javascript/jquery-1.10.2.js"></script>. Page has input fields. I enter some value in input field and click button. Jquery sends input to external php file.

    2) external php file also contains jquery and in the external php file i also included <script type="text/javascript" src="/javascript/jquery-1.10.2.js"></script>. Because if this i got the warning.

    Removed <script type="text/javascript" src="/javascript/jquery-1.10.2.js"></script> from external php file and works without the warning.

    As i understand on loading the first file (file1), i load jquery-1.10.2.js and as the page does not reloads (it sends data to external php file using jquery $.post), then jquery-1.10.2.js continue to exist. So not necessary again to load it.

    0 讨论(0)
  • 2020-11-22 09:44

    In my particular case I was rendering a Rails partial without render layout: false which was re-rendering the entire layout, including all of the scripts in the <head> tag. Adding render layout: false to the controller action fixed the problem.

    0 讨论(0)
提交回复
热议问题