I wanted to get some data from a .json file and use it in another js file.through tutorial i understood that u need to use a ajax function to call the .json file.I used the following function to that however the alert(results) doesnt show any value.can somone plss help???
var results;
var data;
function ajax_get_json() {
    var hr = new XMLHttpRequest();
    hr.open("GET", "Test2.json", true);
    hr.setRequestHeader("Content-type", "application/json", true);
    hr.onreadystatechange = function() {
        if (hr.readyState == 4 && hr.status == 200) {
            var data = JSON.parse(hr.responseText);
            //results=document.getElementById("results");                              
            //results.innerHTML=data.user + " " +data.country;
            results = data.user;
        }
    }
    hr.send(null);
    //results.innerHTML = "requesting...";
    }
ajax_get_json()
    alert(results);
 
     
     
     
     
    