• AJAX JSON类型返回


    文本样式和下拉样式

    <!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>&nbsp;<span>姓名:"+data[1]
                    +"</span>&nbsp;<span>性别:"+data[2]
                    +"</span>&nbsp;<span>生日:"+data[4]
                    +"</span>";
                    
                    $("#xinxi").html(str);
                    
                    }
                
                })
            
            })    
            
            
    });
    </script>
    </html>
    View Code
    <?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);
    View Code
    <?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]);
    View Code
  • 相关阅读:
    Microsoft EBooks
    JavaScript 数据访问(通译自High Performance Javascript 第二章) [转]
    time random sys os模块
    configparser logging collections 模块
    序列化模块和hashlib模块
    内置方法
    面向对象进阶
    property classmethod staticmethod的用法
    归一化设计,抽象类和接口类,接口隔离操作
    面向对象的三大属性
  • 原文地址:https://www.cnblogs.com/bilibiliganbei/p/5616291.html
Copyright © 2020-2023  润新知