i have i think a global variable problem. Watch this:
function more_elems() {
var ret = [];
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var JSONObject = JSON.parse(xmlhttp.responseText);
for (i=0;i<5;i++){
ret[i] =
{
id: JSONObject[i].id,
nombre: JSONObject[i].nombre,
mensaje: JSONObject[i].mensaje,
ult_m: JSONObject[i].ultima_modificacion
};
}
alert(ret);
}
}
xmlhttp.open("GET","somewesite.com",true);
xmlhttp.send();
return ret;
So im trying to return the ret array but it returns undefined. However if i do an alert inside the xmlhttp.onreadystatechange=function() it does show the array with the json object. I'm not sure what the problem is =/.
Thanks in advance.