Ver Mensaje Individual
  #15 (permalink)  
Antiguo 27/08/2013, 18:50
Maru77
 
Fecha de Ingreso: agosto-2003
Mensajes: 524
Antigüedad: 20 años, 8 meses
Puntos: 5
Respuesta: pasar variable con ajax y php

acá está el código completo, honestamente no se que estoy haciendo mal

Código PHP:
<?php
include('loader.php'); //carga db

$conn = new conection();
$rs = new RecordSet($conn);

$sql="SELECT * FROM insumos ORDER BY insumo DESC";
$insumos $rs->get_object_list($sql);

unset(
$rs);
unset(
$conn);
?>
Código HTML:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 

<script type="text/javascript">  
$(document).ready(function(){  
    $('#boton_cargar').click(function() {   
		var nombre = $("#nombre").val(); 
	    var insumos = $("#insumos").val(); 
        $.ajax({ 
			type: "GET",           
			
			url: 'resultados.php?nombre='+nombre+'&insumos='+insumos, 
			  
            success: function(data) {  
                $('#resultados').html(data);  
                $('#resultados div').slideDown(1000);  
            }  
        });  
    });  
  
});  
</script>  

</head>
<body> 

Código HTML:
<form>
<input id="nombre" name="nombre" type="text" />

<select id="insumos" name="insumos">
<?php foreach($insumos as $in){ ?> 
       <option id="<?php $in->id_insumo ?>" ><?php echo $in->id_insumo ?></option>
<?php }?>
</select>

<input name="boton_cargar" id="boton_cargar" type="button" value="buscar" />
</form>

<div id="resultados">
</div>


</body>
</html> 
resultados.php

Código PHP:
<?php
include('loader.php');

$conn = new conection();
$rs = new RecordSet($conn);
 

if(isset(
$_GET['nombre']) && ($_GET['insumos']))
$sql="SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON  insumos.id_insumo = alquiler.id_insumo WHERE `clientes.nombre` = '".$_GET['nombre']."' AND `alquiler.id_insumo` = '".$_GET['insumos']."'";
else
die(
'error');

 
unset(
$rs);
unset(
$conn);
?>
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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body> 
Código PHP:
<?php echo $nombre?>

<?php foreach($resultados as $res){ ?> 
                    

                            <?php echo $res->nombre ?> | |
                            <?php echo $res->insumo ?><br />
                        
                        <?php }?>
Código HTML:
</body>
</html> 
__________________
Saludos!!!
Maru.-