I know that due the nature of asynchronous XMLHTTPRequest it is impossible to return the responseText value in javascript. I've managed to find a workaround the issue by calling a workaround function which pastes the reponseText into whatever ID I provide the function with. However now I've stumbled on the problem again as I need to retrieve a JSON file and return the value of it. I’ve tried injecting responseText into a provided variable however it did not work, I've also tried adding an “interface-like” file which would do that for me, however none of the above worked. Are there any knows workarounds the issue?
function httpGetJson( file, type) {
        self.httpState(true);
        try{
            var type = type || true;
            var http = self.http();
            http.onreadystatechange = function () {
                if (this.readyState == 4 && this.status == 200){
                    returnJson(this.responseText);
                }
            }
            http.open("GET", "json/" + file, type);
            http.send();
        }catch (err){
            return log.error("http.httpGetJson", err.message);
        }
        self.httpState(false);
    }
see all on codepen http://codepen.io/mecostav/pen/JNdovR
 
    