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

Ya no se que hacer

Estas en el tema de Ya no se que hacer en el foro de Frameworks JS en Foros del Web. Hace un tiempo pedi ayuda, para un codigo enrevesado que me estaba dando problemas: http://www.forosdelweb.com/showthread.php?t=476818 Al no encontrar nadie que me diese una solución, simplifique ...
  #1 (permalink)  
Antiguo 16/04/2007, 02:53
Avatar de bichomen  
Fecha de Ingreso: junio-2003
Ubicación: Barcelona y alrededores, España
Mensajes: 877
Antigüedad: 20 años, 10 meses
Puntos: 2
Ya no se que hacer

Hace un tiempo pedi ayuda, para un codigo enrevesado que me estaba dando problemas:

http://www.forosdelweb.com/f127/function-onload-476818/

Al no encontrar nadie que me diese una solución, simplifique las cosas y cambie un poco la extructura, quedandomen de esta manera:

ajax.js
Código HTML:
/// Cargar diferentes includes en una página:

var http_request = false;

function makeRequest(rutas)
{
	http_request = false;

	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType("text/xml");
			// Ver nota sobre esta linea al final
		}
	}	
	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("ERROR :( No es posible crear una instancia XMLHTTP");
		return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open("GET", rutas, true);
	http_request.send(null);

}

function alertContents() 
{

	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			alert(http_request.responseText);
		} 
		else 
		{
			alert("Hubo problemas con la petición.");
		}
	}

}

function XHConn()
{
	var xmlhttp, bComplete = false;
	try 
	{ 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch (e) 
	{ 
		try 
		{ 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		catch (e) 
		{ 
			try 
			{ 
				xmlhttp = new XMLHttpRequest(); 
			}
			catch (e) 
			{ 
				xmlhttp = false; 
			}
		}
	}
	if (!xmlhttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone)
	{
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();
			
		try 
		{
			if (sMethod == "GET")
			{
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			}
			else
			{
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			}
				
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && !bComplete)
				{
					bComplete = true;
					fnDone(xmlhttp);
				}
			};
					
			xmlhttp.send(sVars);
		}
		catch(z) 
		{	
			return false; 
		}
		return true;
	};
	return this;
}

function cargar_contenido(capas, rutas) 
{ 
	//var capas=capas; 
	//alert(capas);
	document.getElementById(capas).innerHTML = "<p>Cargando...</p>"; 
	var myConn = new XHConn(); 
	if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
	
	var peticion = function (oXML) 
	{ 
		document.getElementById(capas).innerHTML = oXML.responseText; 
	}; 
	myConn.connect(rutas, "GET", "", peticion); 
}
index.php
Código HTML:
<head>
<script type="text/javascript" language="javascript">
function cargar(ruta,id)
{
	cargar_contenido("foto", "includes/foto.php?f=" + id); //Foto arriba a la izquierda
	cargar_contenido("fotos", "includes/fotos.php?f=" + id); //Fotos arriba a la derecha
	cargar_contenido("titulo", "includes/titulos.php?valor=" + id); //Titulo del marco
	cargar_contenido("banners", "includes/banners.php?b=" + id); //banners
if(id == 11) //FORO
	{
		cargar_contenido("mayor9", ruta); //Tabla inferior derecha
	}
	else
	{
		cargar_contenido("mayor9", "includes/enlace.php?id=" + id + "&ruta=" + ruta); //Tabla inferior derecha
	}
}
</script>	
<head>
<body>
....
<div id="mayor9">
		<?php include("includes/enlace.php"); ?>
	</div>
....
</body> 
menu.php
Código HTML:
<a href="javascript:cargar('includes/restaurantes.php','3');">enlace</a><br> 
enlace
Código HTML:
<script type="text/javascript" language="javascript">

		//////////////recuperar variables por GET
		enviado=location.href.split("?");  
		igualdades=enviado[1].split("&");  

		for(a=0;a<igualdades.length;a++)
		{  
			igualdades[a]=igualdades[a].split("+").join(" "); 
			valores=igualdades[a].split("=");  
			eval("var "+valores[0]+"='"+valores[1]+"'");  
		}  
		///////////////////////////////////////////

		//document.write(id + "<br />");
		//document.write(ruta + "<br />");
		var rut = "Esto es una variable";

		if(ruta)
		{
			cargar_contenido("anuncios", "anuncios.php?a=" + id);
			cargar_contenido("detalles", ruta);
		}
		else
		{
			cargar_contenido("anuncios", "a.php");
			cargar_contenido("detalles", "inicio.php");
		}

</script>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="157" height="627" valign="top" bgcolor="#FBF7EB" style="border-left:1px solid #000000;border-right:1px solid #000000;padding:8px;">				

<div id="anuncios">
	
</div>

</td><td width="436" valign="top">
			
	<table width="436" border="0" cellpadding="0" cellspacing="0">
	<tr><td width="436" height="627" valign="top" class="solidos" style="padding:22px">
	<div align="left" class="style3"><div id="detalles">
		<script>document.write("variable: " + rut);</script>
	</div></div>
	</td></tr>
	</table>
	
</td></tr>
</table> 
En caso es que cuando cargo el index, el ajax interpetra el codigo y carga en el div mayor9 enlace.php, pero parece que no interpreta el javascript, nunca lo ejecuta, por que??


bichomen
__________________
"Se sabe con exactitud, con cuanta imprecisión, se sabe algo"
Linux Registered User #320332

Última edición por bichomen; 16/04/2007 a las 04:02
  #2 (permalink)  
Antiguo 16/04/2007, 14:46
Avatar de MaBoRaK  
Fecha de Ingreso: abril-2003
Ubicación: La Paz - Bolivia
Mensajes: 2.003
Antigüedad: 21 años
Puntos: 35
Re: Ya no se que hacer

loading......

Ahorrate trabajo, porque no encapsulas el JAVASCRIPT QUE VAS A USAR en tu proceso en un solo archivo u objeto y evitas tener que cargarlo....
y si persistes en esto, lee:

http://josephsmarr.com/2007/01/31/fi...al-scope-in-ie
y
http://ajaxian.com/archives/evaling-...ndowexecscript <-- importante.


connection closed.
__________________

Maborak Technologies
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 16:35.