Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/11/2009, 10:51
Bibliotec
 
Fecha de Ingreso: enero-2002
Mensajes: 182
Antigüedad: 22 años, 3 meses
Puntos: 0
Problema con un return

Estoy intentando hacer algo muy simple pero no funciona

Código:
function createRequestObject(){
      var peticion;
      var browser = navigator.appName;
            if(browser == "Microsoft Internet Explorer"){
                  peticion = new ActiveXObject("Microsoft.XMLHTTP");
            }else{
                  peticion = new XMLHttpRequest();
}
return peticion;
}


var http = new Array();
function ObtDatos(url){
      var act = new Date();
      http[act] = createRequestObject();
      http[act].open('get', url);
      http[act].onreadystatechange = function() {
      if (http[act].readyState == 4) {
            if (http[act].status == 200 || http[act].status == 304) {
		  		var texto; 
				texto = http[act].responseText;
				 return texto;
			}
		}
	}
	http[act].send(null);
}

document.write(ObtDatos("http://midireccion/datos.php"));
Me dice que undefined si lo pongo directamente el document.write en la función con "texto" me lo hace bien no funciona el return y no tengo ni idea de pq.

Un slaudo y gracias.