Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the three-level linkage between AJAX and WebService in provinces, cities and counties

Shulou Source: shulou.com Published: 2022-06-03 08:39:22 09月11日 Update

Editor to share with you how AJAX and WebService achieve the three-level linkage of provinces, cities and counties, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

-- WebService1.asmx--

The code is as follows:

/ / to allow this Web service to be called from a script using ASP.NET AJAX, uncomment the following line.

[System.Web.Script.Services.ScriptService]

Public class WebService1: System.Web.Services.WebService

{

[WebMethod]

Public string HelloWorld ()

{

Return "Hello World"

}

[WebMethod]

Public List GetProvince ()

{

BLL.province bpro = new BLL.province ()

List list = bpro.GetListModel ()

Return list

}

[WebMethod]

Public List GetCityByPro (string proid)

{

BLL.city bcity = new BLL.city ()

List list = bcity.GetListModel ("father='" + proid + "'")

Return list

}

[WebMethod]

Public List GetAreaByCity (string cityid)

{

BLL.area barea = new BLL.area ()

List list = barea.GetListModel ("father='" + cityid + "'")

Return list

}

-- HTMLPage1.htm--

The copy code is as follows:

Select

{

Width: 150px

}

$(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; iTunes +) {

Stroption + =''

Stroption + = result.d [I] .provincename

Stroption + =''

}

$('# 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; iTunes +) {

Strocity + =''

Strocity + = result.d [I] .cityname

Strocity + =''

}

$('# 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; iTunes +) {

Stroarea + =''

Stroarea + = result.d [I] .areaname

Stroarea + =''

}

$('# searea') .append (stroarea)

}

})

})

})

Address

Please select--

Province

Please select--

Market

Please select--

County

Note: using a three-tier architecture, the dal layer writes some methods

The above is all the contents of the article "how to achieve the three-level linkage between AJAX and WebService at the provincial, municipal and county levels". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code article selection province and city content not much address most method more architecture comments knowledge script industry information information channel channel reference learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Huawei NVidia Shulou Tech Info