Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/05/2008, 14:44
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 17 años
Puntos: 20
Re: Pasar variable sin cambiar pagina

si se puede... y justamente con ajax se hace..

Pagina 1:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Script>
function pasadato(){
var dato = document.getElementById('textbox').value;
//alert(dato);
OpenPage('2.php?textbox='+dato);
}
function toggle(what) {
        var aobj = document.getElementById(what);
        if( aobj.style.display == 'none' ) {
               aobj.style.display = '';
        } else {
               aobj.style.display = 'none';
        }
}
function CrearXMLHttp(){
	XMLHTTP=false;
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
// suponiendo que tu div se llama loading
function OpenPage(url){
	req=CrearXMLHttp();
	if(req){
		req.onreadystatechange = manejador;
		req.open("POST",url,true);
		req.send(null);
                toggle('loading'); // ojo aqui
	}
}
function manejador(){
	if(req.readyState == 4){
		if(req.status == 200){
                        toggle('loading'); // ojo aca
			document.getElementById("tdc").innerHTML=req.responseText;
		}else{
			alert("Error"+req.statusText)
		}
	}
}
</Script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p><?php if ($_POST['Algo'] != ""){ ?>Valor recibido por $_POST['Algo']:&nbsp;<strong><?php echo htmlentities($_POST['Algo']); ?><strong><?php } ?>&nbsp;</p>
<table width="200" border="0">
  <tr>
    <td id="tdc"><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div><p>Valor a pasar: 
  <input name="textbox" type="text" id="textbox" value="1" size="8" />
</p></td>
  </tr>
</table>
<p><a href="javascript:pasadato();">Pasar Valor</a></p>
<p>
  <label>
  <input type="submit" name="button" id="button" value="enviar" />
  </label>
</p>
</form>
<p>&nbsp;</p>
</body>
</html>



Pagina 2:

Código HTML:
<div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div>Valor Pasado: <?php echo htmlentities($_GET['textbox']); ?>
<input type="hidden" name="Algo" id="Algo" value="<?php echo htmlentities($_GET['textbox']); ?>">

__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)