0

I use the jquery.load feature for loading page to div on several pages of my project and I keep getting deprecated warning in console. Please how can I resolve this?

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

  <script>
    $(document).on('change', 'select#class_id', function () {
        var class_id = $(this).val();
        $('p#content').load('class.php?cid='+class_id);
    });
</script>

Need help using this

$("p#content").on("load", function() {
    //url
});

Is there a way to load these pages without warning.

Mysterio4
  • 331
  • 2
  • 12
  • use `$.get(url, data, success)` (https://api.jquery.com/jQuery.get/) – Simon Hänisch Sep 19 '16 at 09:13
  • 1
    @SimonHänisch How would that fix warning? – A. Wolff Sep 19 '16 at 09:16
  • Ok I will try that – Mysterio4 Sep 19 '16 at 09:17
  • `$('p#content').load('class.php');` and `$("p#content").on("load", function() {...])` are two different things: [first one](http://api.jquery.com/load/) and [second one](https://api.jquery.com/load-event/) – A. Wolff Sep 19 '16 at 09:19
  • Be aware, your best bet would be to upgrade to jq 3.x – A. Wolff Sep 19 '16 at 09:20
  • yeah i am using jquery 3.1 but have little knowledge on these errors, I thought the error was being triggered by the load(). I will just have to switch and refactor my code to `$.get` – Mysterio4 Sep 19 '16 at 09:23
  • @Mysterio4 Humm, i don't see how switching your code to `$.get` would remove this warning – A. Wolff Sep 19 '16 at 09:26
  • Then that's a lot for me to handle. I do not know what to do about that cause its just 3 lines of javascript code on that page – Mysterio4 Sep 19 '16 at 09:34
  • BUT have you try as in dupe: `$.ajaxPrefilter(function( options, originalOptions, jqXHR ) { options.async = true; });` before you bind `change()` event??? This would make the warning disappear but you could face other issue regarding targeted page script being loaded asynchronously – A. Wolff Sep 19 '16 at 09:48

0 Answers0