ajax.net +jquery 无刷新三级联动的实例代码(2)

$.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/loadarea",
                    data: "{fatherid:'" + $('#Select2 option:selected').val() + "'}",
                    success: function (result) {
                        var str3;
                        for (var i = 0; i < result.d.length; i++) {
                            str3 += "<option value=" + result.d.areaID + ">";
                            str3 += result.d[i].areaname;
                            str3 += result.d[i].father;

                        }
                        $('#Select3').append(str3);
                    }
                })
            })
        })

    </script>
</head>
<body>
   省:
    <select>
        <option>--请选择--</option>
    </select>
    市:
    <select>
        <option>--请选择--</option>
    </select>
    县:
    <select>
        <option>--请选择--</option>
    </select>
</body>
</html>

webservice:

复制代码 代码如下:


 [WebMethod]//加载省
        public List<Model.province> loadprovince()//为什么要用list因为这里出从前的值不可能一个实例是多个model实例,一个实例就是一条记载这样做防止字段错误
        {
            BLL.province bp = new BLL.province();
            List<Model.province> list=bp.getlistModel();
            return list;
        }
        [WebMethod]//加载市
        public List<Model.city> loadcity(string fatherid)
        {
            BLL.city bc = new BLL.city();
            List<Model.city> list = bc.getlistmodel(fatherid);
            return list;
        }
        [WebMethod]//加载县
        public List<Model.area> loadarea(string fatherid)
        {
            BLL.area ba = new BLL.area();
            List<Model.area> list = ba.getlistmodel(fatherid);
            return list;

        }
    }
}

DAL--area

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgfws.html