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

报告相同问题?

悬赏问题

  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致