文本样式和下拉样式
<!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>无标题文档</title> <script src="jquery-1.11.2.min.js"></script> </head> <body> <div>请输入代号:<input type="text" id="code" /> <input type="button" value="查询" id="btn" /> </div><br /> <div id="name"></div><br /> <div>请选择:<select id="sel"> <option value="p001">唐墨墨</option> <option value="p002">断点</option> <option value="p003">等等</option> </select></div><br /> <div id="xinxi"></div> </body> <script type="text/javascript"> $(document).ready(function(e) { $("#btn").click(function(){ var code=$("#code").val(); $.ajax({ url:"AJAX3chuli.php", data:{code:code}, type:"POST", dataType:"JSON", success: function(data){ $("#name").text(data.name); } }) }) $("#sel").change(function(){ var code=$(this).val(); $.ajax({ url:"AJAX3achuli.php", data:{code:code}, type:"POST", dataType:"JSON", success: function(data){ var str="<span>代号:"+data[0] +"</span> <span>姓名:"+data[1] +"</span> <span>性别:"+data[2] +"</span> <span>生日:"+data[4] +"</span>"; $("#xinxi").html(str); } }) }) }); </script> </html>
<?php $code=$_POST["code"]; include("dbda.class.php"); $db=new dbda(); $sql="select name from info where code='{$code}'"; $attr=$db->Query($sql); //做一个关联数组 $arr=array(); $arr["name"]=$attr[0][0]; //将数组转化为json数据 echo json_encode($arr);
<?php $code=$_POST["code"]; include("dbda.class.php"); $db=new dbda(); $sql="select * from info where code='{$code}'"; $attr=$db->Query($sql); echo json_encode($attr[0]);