Ver Mensaje Individual
  #18 (permalink)  
Antiguo 13/06/2012, 16:05
Gothgauss
 
Fecha de Ingreso: marzo-2009
Mensajes: 395
Antigüedad: 15 años, 1 mes
Puntos: 11
Respuesta: Variables de sesion

He creado un ejemplo a pequeña escala para ir entendiendo todo pero no me funciona:

He puesto un input text y un button y una variable de sesion (inicialmente vacia), para que al meter un valor en el text y al pinchar el button, me envie mediante ajax por get a sesion.php la variable.

En sesion.php la recojo mediante una variable de sesión, y en teoría debería imprimir la variable, pero no imprime nada. Aquí el código:


index.php:
Código:
<?session_start();?>
<head>
<script type="text/javascript" src="../js/jquery.js"></script>

<script>

$(document).ready(function(){
			$('#texto').val();
			$('#boton').click(function(){
				$.ajax({
				type:'GET',
				url:'sesion.php',
				data:{"producto":$('#texto').val()}
				});
			
				
			});
});





</script>
</head>
<body>
<input type="text" id="texto" /><input type="button" id="boton" value="dar" /><br />



<?echo "Y aqui la variable de sesion:".$_SESSION['producto'];?>
</body>
y ahora el codigo de sesion.php
Código:
<?session_start();
$_SESSION['producto'] = $_GET['producto'];


?>
EDITO : ME ESTÁ FUNCIONANDO PERO NECESITO REFRESCAR LA PÁGINA, poruqe estoy mostrandolo con php y no recogiendo los datos con ajax para mostrarlos mediante jquery. SE ENVIAR DATOS CON AJAX PERO NO RECOGERLOS... :S

Última edición por Gothgauss; 13/06/2012 a las 16:14