i use this javascript code for a API request to get a JSON.
function loadJSON(url) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType('application/json');
xobj.open('GET', url, false);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == '200') {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
returnval = JSON.parse(xobj.responseText);
}
};
xobj.send(null);
return returnval;
}
The code is in a mouse-click event. The full URL is generated with data from the mouse click. The code is only work with sync. I have tested the code with async, but with this the code don't work. xobj.open('GET', file, true, null, null);
With sync, the console write:
[Deprecation] 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/.
OK, hey! There a many Threads with this question, but i don't found a solution. I use pure JavaScript, no Ajax, no JQuery.