Loading script asynchronously

0

I have an administrative system using adminLTE. In the side menu I load all my scripts asynchronously (at least it was expected). But when I load an HTML asynchronously, and inside that file I load an external javascript, it gives me the following warning:

  

jquery.min.js: 2 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check link .

Follow the code I'm using to load the files

$.ajax(url+"teste").done(function(data) {
    $("#ajax-content").html(data);
    $('#loadingMenu').remove(); // Retira o gif de loading
});

The file I load is this:

<div class="box">
    <h1>HTML carregado assincronamente</h1>
</div>
<script src="meuScript.js"></script>

Placing the direct javascript code in the HTML file does not generate any errors.

<div class="box">
    <h1>HTML carregado assincronamente</h1>
</div>
<script>
   alert('agora não gera aviso');
</script>

How do I load this script without having to put it on the same HTML page?

    
asked by anonymous 09.02.2018 / 18:58

1 answer

3

The message says the opposite of what you understood;

What is being discontinued (has become obsolete) is the SYNCHRON (which locks the browser many times), for example this is synchronous :

xhr.open("GET", "/foo/bar", false);

And this is ASYNCHRONOUS:

xhr.open("GET", "/foo/bar", true);

In this answer I explain what is Ajax and Sjax:

Of course the above code is pure JS, but jQuery internally uses JavaScript.

However as @ValdeirPsr said, it is a problem in the jQuery.parseHTML (and / or dependencies) function, used internally in the $(seletor).load("..."); function

In other words, it is a bug in jQuery, and it is likely that soon they will correct it.

    
09.02.2018 / 20:05