zoukankan      html  css  js  c++  java
  • ajax加php实现三级联动

    js代码

    <script type="text/javascript">
        function get_next(t,pid){  //当前元素的id,当前option的value,一般都是id吧?反正我的是
            $.ajax({
                type: "POST",
                url:  "/index.php?type=company&m=action&a=getNext",
                data: "pid="+pid,
                dataType: 'json',
                success: function(msg){
                    $("#"+t).next('select').html(msg.str);//拼接html
                }
            });
        }
    </script>

    php代码

    public function getNext()
            {
             
                $next = $sql    //查找数据库pid=post过来的id的sql
                $str = "<option value=''>请选择</option>";
                foreach ($next as $val) {
                    $str .= "<option value='".$val['id']."'>".$val["name"]."</option>";
                }
                $msg["str"] = $str;
                echo json_encode($msg);
                die();
            }

    可以在任何地方调用,但是还是有个小缺陷,我选择无视。嘻嘻

  • 相关阅读:
    JavaScript中的this相关
    Git进阶操作_1
    Git基本操作_5
    Git基本操作_4
    Git基本操作_3
    Git基本操作_2
    利用Python发送SMTP邮件
    Python JWT使用
    Python中的Asyncio 异步编程
    Python中的抽象类和接口类
  • 原文地址:https://www.cnblogs.com/fufufu/p/6249668.html
Copyright © 2011-2022 走看看