My browser (or the JQuery framework, to be more specific) prints the following warning to the browser's console:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
I understand the warning, but not why it appears. To my understanding the call of asyncFunct() is asynchronous and therefore shouldn't print the warning message.
I'm using this JavaScript code:
var i18nObject;
$(document).ready(function () {
// execute asyncFunct() asynchronously
setTimeout(asyncFunct, 3000);
});
function asyncFunct() {
alert(i18n("rejoin.title"));
}
function i18n(key) {
if (typeof i18nObject == 'undefined') {
// i18n not loaded yet, need to load it first
$.ajax({
url: 'UrlTo/i18n.json',
async: false,
dataType: 'json',
success: function (response) {
i18nObject = response;
}
});
}
if (i18nObject.hasOwnProperty(key)) {
// key found
return i18nObject[key];
} else {
// key not found
return key;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
To face some concerns (from the comments) about async: false
: This was deliberately chosen, as I need the function to return a value. I understand that using synchronous calls is a bad idea if they lock the UI. But why does this apply to my problem here? I want the call to asyncFunct() to be asynchronous.
Why am I receiving this warning, and is it possible to disable it? (to prevent unnecessary text in the console)