-------------------------------------Webservice1.asmx---------------------------------------
Copy Code code as follows:
To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink.
[System.Web.Script.Services.ScriptService]
public class WebService1:System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld ()
{
Return to "Hello World";
}
[WebMethod]
Public list<model.province> getprovince ()
{
Bll.province Bpro = new Bll.province ();
list<model.province> list = Bpro. Getlistmodel ();
return list;
}
[WebMethod]
Public list<model.city> Getcitybypro (string proid)
{
Bll.city bcity = new bll.city ();
list<model.city> list = bcity. Getlistmodel ("father= '" + proid + "");
return list;
}
[WebMethod]
Public list<model.area> getareabycity (string Cityid)
{
Bll.area Barea = new Bll.area ();
list<model.area> list = Barea. Getlistmodel ("father= '" + Cityid + "");
return list;
}
----------------------------------htmlpage1.htm----------------------------
Copy Code code as follows:
<title></title>
<style type= "Text/css" >
Select
{
width:150px;
}
</style>
<script src= "Js/jquery1.7.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/getprovince",
Data: "{}",
Success:function (Result) {
var stroption = ';
for (var i = 0; i < result.d.length; i++) {
Stroption + = ' <option value= ' + Result.d[i].provinceid + ' > ';
Stroption + = Result.d[i].provincename;
Stroption + = ' </option> ';
}
$ (' #seprovince '). Append (stroption);
}
})
$ (' #seprovince '). Change (function () {
$ (' #secity option:gt (0) '). Remove ();
$ (' #searea option:gt (0) '). Remove ();
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/getcitybypro",
Data: "{proid: '" + $ (This). Val () + "'}",
Success:function (Result) {
var strocity = ';
for (var i = 0; i < result.d.length; i++) {
Strocity + = ' <option value= ' + Result.d[i].cityid + ' > ';
Strocity + = Result.d[i].cityname;
Strocity + = ' </option> ';
}
$ (' #secity '). Append (strocity);
}
})
})
$ (' #secity '). Change (function () {
$ (' #searea option:gt (0) '). Remove ();
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/getareabycity",
Data: "{cityid: '" + $ (This). Val () + "'}",
Success:function (Result) {
var stroarea = ';
for (var i = 0; i < result.d.length; i++) {
Stroarea + = ' <option value= ' + result.d[i].areaid + ' > ';
Stroarea + = Result.d[i].areaname;
Stroarea + = ' </option> ';
}
$ (' #searea '). Append (Stroarea);
}
})
})
})
</script>
<body>
<table>
<tr>
<td>
Address
</td>
<td>
<select id= "Seprovince" >
<option>--Please select--</option>
</select>
Province
<select id= "Secity" >
<option>--Please select--</option>
</select> City
<select id= "Searea" >
<option>--Please select--</option>
</select> County
</td>
</tr>
</table>
</body>
Note: The three-tier architecture is used, and the DAL layer writes some methods