Ver Mensaje Individual
  #7 (permalink)  
Antiguo 13/12/2009, 09:21
risingforce308
 
Fecha de Ingreso: diciembre-2009
Mensajes: 7
Antigüedad: 15 años, 2 meses
Puntos: 0
Respuesta: Duda con paso de variables por URL

Gracias amigo! Pero que hago? Sustituyo:

Código HTML:
<body> 
    <div> 
        <a href="index.php?var=1"><img src="imagen.jpg"></a> 
    </div> 
    <div id="nombredeldiv"> 
        <?PHP 
            $var = $_GET['var']; 
                if ($var== "") include("textodeprueba.txt");  
                else echo "<a href='index.php'>TEXTO NUEVO</a>"; 
        ?> 
    </div> 
</body> 
Por esto:

Código HTML:
<body>
<script language="javascript">
var xhr;
function startAjax(v){
	if(window.XMLHttpRequest){
		xhr=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
xhr.open("GET","tuArchivo.php?var="+v);
xhr.onreadystatechange=function (){
	if(xhr.readyState==4){
	if(xhr.status==200){
		var div=document.getElementById("algo");
        //esta es la respuesta de tu php
		div.innerHTML=xhr.responseText;
		}
	}
}
xhr.send(null);	
}
</script>
<a href="javascript: startAjax('1')"><img src="imagen.jpg"></a>
<div id="algo"></div>
</body> 

??


Cita:
Iniciado por jackson666 Ver Mensaje
Código HTML:
<body>
<script language="javascript">
var xhr;
function startAjax(v){
	if(window.XMLHttpRequest){
		xhr=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
xhr.open("GET","tuArchivo.php?var="+v);
xhr.onreadystatechange=function (){
	if(xhr.readyState==4){
	if(xhr.status==200){
		var div=document.getElementById("algo");
        //esta es la respuesta de tu php
		div.innerHTML=xhr.responseText;
		}
	}
}
xhr.send(null);	
}
</script>
<a href="javascript: startAjax('1')"><img src="imagen.jpg"></a>
<div id="algo"></div>
</body> 
Con eso y tu php, modificas el contenido de ese div sin recargar. Lo que no me queda bien en claro es para que necesitas que en la url se vea el paso de variables... Si el php se ejecuta igual, el parametro se le pasa por GET... La verdad no entiendo