Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/07/2008, 10:22
Avatar de javiro
javiro
 
Fecha de Ingreso: febrero-2006
Mensajes: 48
Antigüedad: 18 años, 2 meses
Puntos: 1
Respuesta: Las propiedades readyState y status

Claro clodoviro! ya lo explique cuando inicie el tema, pero pongo el codigo javascript entero:

Código:
//Crear una variable de Bool para comprobar si se está usando Internet Explorer.
	var xmlhttp = false;
	
	//Comprobar si se está usando IE.
	try {
		//Si la versión de javascript es superior a la 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//Si no, utilizar el tradicional objeto ActiveX.
		try {
			//Si se está usando Internet Explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//En caso contrario no se debe estar usando Internet Explorer.
			xmlhttp = false;
		}
	}
	
	//Si no se está usando IE, crear una instancia ActiveX del objeto.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	function makerequest(serverPage, objID) {
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

///este If es el que no comprendo, porque cuando yo pruebo este codigo nunca entra porque el valor xmlhttp.readyState nunca es 4 y xmlhttp.status nunca es 200
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
Entonces si la to la linea if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
y ejecuto sin verificar la linea obj.innerHTML = xmlhttp.responseText; me funciona el script bien.
Pero entonces, porque tengo que validar readState y status si nunca entra con esos valores???