Ver Mensaje Individual
  #9 (permalink)  
Antiguo 08/06/2012, 10:35
Avatar de SnakeCode
SnakeCode
 
Fecha de Ingreso: mayo-2012
Ubicación: Lima - Perú
Mensajes: 23
Antigüedad: 12 años
Puntos: 1
Respuesta: problema XMLHttpRequest

Holas, disculpen por abrir el tema, pero tengo un problema igual con incompatibilidad en Chrome, es un formulario que tiene el siguiente codigo Ajax:

Código:
   var http_request = false;
   var clicks	  = 0;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('Hubo un problema en la Solicitud.');
         }
      }
   }
   
   function get(obj) {
	    var varSex="";
		  if(document.getElementsByName("Sexo")[0].checked){
				varSex = document.getElementsByName("Sexo")[0].value;
		  }else if(document.getElementsByName("Sexo")[1].checked){
				varSex = document.getElementsByName("Sexo")[1].value;
			}else{
				varSex = "";
			}
      var poststr = "Nombre=" + encodeURI( document.getElementById("Nombre").value ) +
            "&Pais=" + encodeURI( document.getElementById("Pais").value ) +
			"&Telefono=" + encodeURI( document.getElementById("Telefono").value )+
			"&Correo=" + encodeURI( document.getElementById("Correo").value )+
			"&Sexo=" + encodeURI(varSex) +
			"&Edad=" + encodeURI( document.getElementById("Edad").value )+
			"&Permanencia=" + encodeURI( document.getElementById("Permanencia").value )+
			"&Fecha=" + encodeURI( document.getElementById("Fecha").value )+
			"&Encontro=" + encodeURI( document.getElementById("Encontro").value )+
			"&Comentarios=" + encodeURI( document.getElementById("Comentarios").value )+
			"&url=" + encodeURI( document.getElementById("url").value )+
			"&capt=" + encodeURI( document.getElementById("capt").value )+			  
			"&Submit=" + encodeURI( document.getElementById("Submit").value );
      makePOSTRequest('http://www.vivatoursperu.com/captcha/c-envio-solicitud.php', poststr);
   }

   function write_captcha(){
		define('Nombre', 'string', 'Nombre');
		define('Correo', 'email', 'E-mail');
		define('Pais', 'string', 'País');
		define('capt', 'string', 'Captcha');
   	clicks++;
   	document.getElementById('capt').value		= ''
	  document.getElementById('captcha_id').innerHTML = '<img src="http://www.vivatoursperu.com/captcha/captcha_img.php?clicks=' + clicks + '" border="0" alt="" /><a href="#" onclick="write_captcha();"><img src="http://www.vivatoursperu.com/captcha/png_bank/refresh.gif" border="0" alt="" /></a><br />Escribe los caracteres de la imagen';
   return false;
   }
Me funciona en Firefox, IE, Safari, Opera ... pero no en Chrome. No es mi codigo ni yo he desarrollado el website, pero me han mandado a revisar este website y el problema de porque no funciona el envio del formulario en Chrome. Gracias de antemano

Saludos