the global variable failed to be assigned after AJAX got the return value. How to solve this problem?
Thecode is as follows. Failed to assign values to words [I] and exps [I]
var index = 0;
var words = new Array();
var exps = new Array();
function addWords(shift){
var add = new XMLHttpRequest();
add.onreadystatechange = function(){
if (add.readyState == 4 && add.status == 200){
var json = eval( "(" + add.responseText + ")" );
var i;
for (i in json.items){
words[i] = json.items[i].word;
exp[i]= json.items[i].exp;
}
}
}
add.open("GET", "get.php", true);
add.send();
}