Question from begginer one. By the AJAX function i'm getting an array in JSON from my script. In the example i want to save responseText (array) in global variable because of my need to use it in another function(s). And I just cannot. I hope there is a way to do it but I cannot find one.
var out;
var arr; //global variable
function ajax(kat1) {
if (kat1 == "") {
document.getElementById("div1").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
arr=JSON.parse(this.responseText); //here might be the problem
}
}
xmlhttp.open("GET","script.php?q="+kat1,true);
xmlhttp.send();
}
}
function show(response, i)
{
var arr1 = arr;
out = "Question"+arr1[i].id+": "+arr1[i].question+"? ";
document.getElementById("quizblock10").innerHTML = out;
}