How to pass DATA from AJAX in the global scope?

Hi all. The question is. Request to the server for the json file, everything is OK. Then this json should be handled, and to pass it in global scope fails.
Example:
var request = new XMLHttpRequest();
 request.open('GET', 'data.json', true);
 request.onload = function() {
 if (request.status >= 200 && request.status < 400) {
 // Success
 var data= JSON.parse(request.responseText).join(", ");
 } 
};
 request.onerror = function() {
};
request.send();

//how to get DATA here?
June 14th 19 at 20:06
1 answer
June 14th 19 at 20:08
Solution
window.data= JSON.parse(request.responseText).join(", ");
however, notice that storing anything like that in global scope is bad practice - therese commented on June 14th 19 at 20:11
I agree, it's just the answer to the question - peter.Armstro commented on June 14th 19 at 20:14
You can simply collect all functions related to this task, one object, and to assign such data to its members. Global will not be garbage. - chelsea13 commented on June 14th 19 at 20:17
Yes - peter.Armstro commented on June 14th 19 at 20:20

Find more questions by tags JavaScriptAJAX