Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Ajax no funciona en Firefox pero en Chrome Sí!

Estas en el tema de Ajax no funciona en Firefox pero en Chrome Sí! en el foro de Frameworks JS en Foros del Web. ¿Que tal? tengo el siguiente codigo: Código HTML: function newAjax() { var xmlHttp=null; if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) xmlHttp = new ...
  #1 (permalink)  
Antiguo 26/12/2010, 01:07
Avatar de javiertroya  
Fecha de Ingreso: mayo-2009
Ubicación: Valencia
Mensajes: 15
Antigüedad: 15 años
Puntos: 2
Ajax no funciona en Firefox pero en Chrome Sí!

¿Que tal? tengo el siguiente codigo:

Código HTML:
function newAjax()
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function cambiar_select(divId, tagName, selectName, selectId, funcion, parametro, Width, AddEvent)
{
	url = baseurl+'php/php_selects.php?funcion='+funcion+'&parametro='+parametro+'&tagName='+tagName;
	ajax = newAjax();
	ajax.onreadystatechange = function()
	{
		var div = document.getElementById(divId);
		div.innerHTML = '';
		
		if(ajax.readyState == 4)
		{
			var xml = ajax.responseXML;
			var opt = xml.getElementsByTagName(tagName);
			
			var select = document.createElement('select');
			select.name = selectName;
			select.id = selectId;
			select.style.width = Width;
			
			var seleccione = document.createElement('option');
			var texto = document.createTextNode('Seleccione');
			seleccione.appendChild(texto);
			seleccione.value = 'seleccione';
			select.appendChild(seleccione);
			div.appendChild(select);
			
			if(estado != 'seleccione')
			{
				for(i=0;i<opt.length;i++)
				{
					var option = document.createElement('option');
					var text = document.createTextNode(opt[i].firstChild.nodeValue);
					option.appendChild(text);
					select.appendChild(option);
				}
				if(AddEvent == 'add')
				{
					addUrl = baseurl+'php/php_selects.php?funcion='+funcion+'_addEvent&parametro=NULL&tagName=NULL';
					addEv = newAjax();
					addEv.onreadystatechange = function()
					{
						if(addEv.readyState == 4)
						{
							funcion = addEv.responseText;
						}
					}
					addEv.open('GET',addUrl,true);
					addEv.send(null);
					addEvent(select,'change',function(){ eval(funcion); },false);
				}
			}
		}
		else
		{
			div.innerHTML = '<img src="'+baseurl+'images/cargando.gif" />';
		}
	}
	
	ajax.open('GET',url, true);
    ajax.send(null);
}
Y en el Php

Código PHP:
require("db.php");
if($_REQUEST)
{
    $funcion = $_REQUEST["funcion"];
    $parametro = $_REQUEST["parametro"];
    $tagName = $_REQUEST["tagName"];
    if(function_exists($funcion))
    {
        echo $funcion($parametro);
    }
    else
    {
        $xml="<?xml version="1.0\"?>\n";
            
$xml.="<marco>\n";
                
$xml.="<".$tagName.">No existen ciudades</".$tagName.">";
            
$xml.="</marco>";
        
header('Content-Type: text/xml');
        echo 
$xml;
    }
}

function 
sel_edo($estado)
{
    global 
$db,$tagName;
    
$xml="<?xml version=\"1.0\"?>\n";
    
$xml.="<marco>\n";
    if(
$ciudades $db->get_results('select * from ciudades where estado = "'.$estado.'"'))
    {
        foreach(
$ciudades as $row)
        {
            
$xml.= "<".$tagName.">".$row->ciudad."</".$tagName.">\n";
        }
    }
    else
    {
        
$xml.="<".$tagName.">No existen ciudades</".$tagName.">";
    }
    
$xml.="</marco>\n";
    
header('Content-Type: text/xml');
    return 
$xml;
}
//FIN FUNCION

//INICIO FUNCION
    
function sel_edo_addEvent($param NULL)
    {
        echo 
"cambiar_codigo(document.getElementById('estado').value,document.getElementById('ciudad_').value)";
    }
//FIN FUNCION
Y funciona perfectamente en Chrome pero no sirve sino hasta estas dos lineas de Javascript:
Código HTML:
select.appendChild(seleccione);
div.appendChild(select);
Yo siempre he usado Xajax pero realmente queria dedicarme a aprender Ajax a puro codigo...

Ademas trabajo con CodeIgniter por eso pueden ver el uso de una variable no definida
Código HTML:
baseurl
Ella es definida en el template que uso de la siguiente forma
Código PHP:
<script>
baseurl = "<?=base_url();?>";
</script>
Si alguien me puede ayudar no tengo otra forma de explicarlo... De antemano gracias!
  #2 (permalink)  
Antiguo 26/12/2010, 12:41
Avatar de javiertroya  
Fecha de Ingreso: mayo-2009
Ubicación: Valencia
Mensajes: 15
Antigüedad: 15 años
Puntos: 2
Respuesta: Ajax no funciona en Firefox pero en Chrome Sí!

Solucionado!

En el codigo Javascript donde esta la linea

Código HTML:
if(estado != 'seleccione')
La variable estado no existe!
La cambio por

Código HTML:
if(parametro != 'seleccione')
Que sí existe

Muchas gracias a los que vieron el mensaje!

Última edición por javiertroya; 27/12/2010 a las 11:41 Razón: Solucionado

Etiquetas: ajax, php, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:27.