weixin_33693070 2013-08-27 22:58 采纳率: 0%
浏览 23

传递变量-Ajax和PHP

I have this simple form wich allows to search and I want to show results into a DIV, so I am using ajax for it.

<script type="text/javascript">  
$(document).ready(function(){  
    $('#boton_cargar').click(function() {   

    var nombre = $("#nombre").val(); 
        $.ajax({ 
        type: "GET",           
        url: 'resultados.php?nombre='+nombre, 
            success: function(data) {  
                $('#resultados').html(data);  
                $('#resultados div').slideDown(1000);  
            }  
        });  
    });  

});  
</script> 




<form>
<input id="nombre" name="nombre" type="text" />

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

<div id="resultados">
   // I want to show results here
</div>

and this is resultados.php

<?php
include('loader.php'); //call db

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

if(isset($_GET['nombre']))

$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']}";
else
die('error');


unset($rs);
unset($conn);
?>

<?php foreach($resultados as $res){ ?> 
    <?php echo $res->nombre ?>
<?php }?>

I don't know what it's wrong, for example if I replace {$_GET['nombre']} for "jhon" I can get the results.

Hope can help me, thank u so much in advance!

  • 写回答

3条回答 默认 最新

  • weixin_33725239 2013-08-27 23:04
    关注

    You need to put quotes around {$_GET['nombre']}

    $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']}'";
    
    评论

报告相同问题?